
I want to change the Amount cell when Qty or Price changed.
Amount = Qty * Price
I tried this code and it’s always giving me ArgumentOutOfRangeException .
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
if (dg_invoices_items.Columns[e.ColumnIndex].Name == "qty")
{
dg_invoices_items[e.RowIndex, 4].Value =Convert.ToString(
Convert.ToInt32(dg_invoices_items[e.RowIndex, 2].Value) *
Convert.ToInt32(dg_invoices_items[e.RowIndex, 3].Value));
}
}
Column indexes start at 0, your column indexes are one too high.
To avoid this you can probably use named columns:
Altough I cannot test any code at the moment, so this might not work.