if (dataGridView1.Rows.Count>1) { DataTable dt = new DataTable(); //fetching the data form the item code or barcode // MessageBox.Show(dataGridView1.Rows[0].Cells["calitem_name"].Value.ToString()); dt = blsto.getallstockbyname((dataGridView1.CurrentRow.Cells["calbar_code"].Value).ToString()); if (dt.Rows.Count > 0) { //get crt price DataTable dts = blcrt.getpricebycrtvalue(dt.Rows[0]["crt_value"].ToString()); decimal crt_price = Convert.ToDecimal(dts.Rows[0]["crt_price"].ToString()); // decimal weight = Convert.ToDecimal(dt.Rows[0]["weight"].ToString()); int quantity = Convert.ToInt32(dt.Rows[0]["quantity"].ToString()); decimal making_charge = Convert.ToDecimal(dt.Rows[0]["labour_charge"].ToString()); decimal stone_price = Convert.ToDecimal(dt.Rows[0]["stone_charge"].ToString()); decimal margin_price = Convert.ToDecimal(dt.Rows[0]["margin_price"].ToString()); decimal past_sell_price = Convert.ToDecimal(dt.Rows[0]["sell_price"].ToString()); decimal todaysellprice = Convert.ToDecimal((weight * crt_price) + margin_price + stone_charge + making_charge); dataGridView1.CurrentRow.Cells["calitem_name"].Value = dt.Rows[0]["item_name"].ToString(); dataGridView1.CurrentRow.Cells["calweight"].Value = dt.Rows[0]["weight"].ToString(); dataGridView1.CurrentRow.Cells["calqty"].Value = dt.Rows[0]["quantity"].ToString(); dataGridView1.CurrentRow.Cells["calrate"].Value = dt.Rows[0]["sell_price"].ToString(); dataGridView1.CurrentRow.Cells["calcrt"].Value = dt.Rows[0]["crt_value"].ToString(); dataGridView1.CurrentRow.Cells["calstoneprice"].Value = dt.Rows[0]["stone_charge"].ToString(); dataGridView1.CurrentRow.Cells["caltotal"].Value = todaysellprice; } else { lbl_barcode.Text = "Set Barcode Again, Can't find Product"; } decimal result = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { result += Convert.ToDecimal(row.Cells["caltotal"].Value); } txtsubtotal.Text = result.ToString(); }
dataGridView1.Rows[rowindex].Cells["column_name or column_index"].Value = your_value;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)