dataGridView1_CellEndEdit
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { int i; i = dataGridView1.SelectedCells[0].RowIndex; int g = dataGridView1.Rows.Count; if (dataGridView1.CurrentCell.ColumnIndex == 0) { if (dataGridView1.Rows[i].Cells[0].Value.ToString() != "") { for (int i4 = 0; i4 < dataGridView1.Rows.Count; i4++) { if (i4 == dataGridView1.Rows.Count - 1 && dataGridView1.Rows[i].Cells[0].Value.ToString() != "") { string item = dataGridView1.Rows[i4-1].Cells[0].Value.ToString(); string sql = "select MRP,Units from list where item ='" + item + "' "; DataTable dt; dt = obj.ReturnDT(sql); if (dt.Rows.Count > 0) { dataGridView1.Rows[i4-1].Cells[1].Value = "1"; string unit = dt.Rows[0]["Units"].ToString(); dataGridView1.Rows[i4-1].Cells[2].Value = unit; string mrp1 = dt.Rows[0]["MRP"].ToString(); dataGridView1.Rows[i4-1].Cells[3].Value = mrp1; dataGridView1.Rows[i4-1].Cells[4].Value = "0"; dataGridView1.Rows[i4-1].Cells[5].Value = mrp1; dataGridView1.Rows[i4-1].Cells[6].Value = mrp1; count = 1; } } } } } if (dataGridView1.CurrentCell.ColumnIndex != 0 && dataGridView1.CurrentCell.ColumnIndex != 6) { string quantity = dataGridView1.Rows[i].Cells[1].Value.ToString(); string mrp = dataGridView1.Rows[i].Cells[3].Value.ToString(); string dis = dataGridView1.Rows[i].Cells[4].Value.ToString(); string rate = dataGridView1.Rows[i].Cells[5].Value.ToString(); string amt = dataGridView1.Rows[i].Cells[6].Value.ToString(); float a = float.Parse(mrp); float b = float.Parse(dis); float rate2 = a - b; dataGridView1.Rows[i].Cells[5].Value = rate2; float a1 = float.Parse(quantity); //float b1 = float.Parse(rate2); float amount = a1 * rate2; float total = 0; dataGridView1.Rows[i].Cells[6].Value = amount; for (int i4 = 1; i4 < dataGridView1.Rows.Count; i4++) { float amt1 = float.Parse(dataGridView1.Rows[i4 - 1].Cells[6].Value.ToString()); total = total + amt1; } label1.Text = total.ToString(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)