I have a datagridView in which there are predefined columns. Suppose there are four columns,let's say A,B,C and D. Column A is for quantity and Column B is for rate and Column C is for discount and Column D is for total.I need a textchanged event like thing for when i enter in Column C the value in Column D should automatically change according to calculation as D=A*B-C. So please advice me how to achieve this. Thank You.
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1)
{
dataGridView1.Rows[e.RowIndex].Cells[14].Value =
((Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[3].Value)) * (Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[7].Value))
- Convert.ToDecimal(dataGridView1.Rows[e.RowIndex].Cells[13].Value));/*taxable*/
}
If you want to change grid when some cell changed value, you can use CellEndEdit
Event
like here:
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
int editedRow = e.RowIndex;
int editedColumn = e.ColumnIndex;
int sum = 0;
for (int i=0;i< dataGridView1.Columns.Count-1 ;i++)
sum += dataGridView1[i, e.RowIndex];
dataGridView1[dataGridView1.Columns.Count-1, editedRow] = sum;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments