You should handle the CellValueChanged
instead, although handling that event may bring you the same effect (if user changes the cell value via UI, the CellValueChanged
is fired only after the cell value is changed and loses focus):
private void dtgVOuchers_CellValueChanged(object sender, DataGridViewCellEventArgs e){
var cell = dtgVOuchers[e.ColumnIndex, e.RowIndex];
if(cell.OwningColumn.Name == "Rate" || cell.OwningColumn.Name == "Supply"){
//update the Amount cell
cell.OwningRow.Cells["Amount"].Value = Convert.ToDecimal(cell.OwningRow.Cells["Rate"].Value) *
Convert.ToDecimal(cell.OwningRow.Cells["Supply"].Value);
}
}
I suppose the value type of the Amount cell is decimal
, you can change the Convert.ToDecimal
to the corresponding converter of the data type.