views:

56

answers:

1

Hello everyone,

I just want to ask. I have a datagridview of Products with columns ProdName, Quantity, SellingPrice, and Total. The Quantity and SellingPrice both has a ReadOnly property set to false. So basically, the user can change values in it during run-time. What I want to know is how can I insert a value in the Total column which is actually the product of the Quantity and the SellingPrice?

Any inputs are welcome. Thanks :)

A: 

You could use the CellValidated event:

private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e)
{
    // TODO: Add proper error handling by checking for null values, 
    // using decimal.TryParse, ...
    var row = dataGridView1.Rows[e.RowIndex];
    int quantity = int.Parse(row.Cells[1].Value.ToString());
    decimal sellingPrice = decimal.Parse(row.Cells[2].Value.ToString());
    row.Cells[3].Value = quantity * sellingPrice;
}
Darin Dimitrov
thanks a lot. :)
Kim Rivera