Auto Compute of Inputs in DataGridView - C#
I just wa开发者_Python百科nt 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 :)
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;
}
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论