[英]Auto Compute of Inputs in DataGridView - C#
我只想問。 我有一個帶有列ProdName,數量,SellingingPrice和Total的Products的datagridview。 Quantity和SellingPrice都將ReadOnly屬性設置為false。 因此,基本上,用戶可以在運行時更改其中的值。 我想知道的是如何在“總計”列中插入一個值,該值實際上是“數量”與“賣價”的乘積?
歡迎任何輸入。 謝謝 :)
您可以使用CellValidated
事件:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.