【发布时间】:2013-01-23 18:15:15
【问题描述】:
为什么网格视图单元格会在小计网格视图的底部自动添加 0?
int qty = 0;
int amount = 0;
int rowtotal = 0;
int subtotal = 0;
int total = 0;
foreach (DataGridViewRow row in itemgridview.Rows)
{
qty = Convert.ToInt32(row.Cells[1].Value);
amount = Convert.ToInt32(row.Cells[2].Value);
rowtotal = qty * amount;
row.Cells[3].Value = rowtotal;
subtotal += rowtotal;
}
total = subtotal;
txtordertotal.Text = total.ToString();
【问题讨论】:
-
他的意思是 GridView 中的“新行”,即您要输入数据以添加行的部分,已经将其小计预填充为 0。
-
它还在计算最后一行的总计,因为它没有任何 qty 和金额的值,它节省了 0,因为小计默认为 0。
标签: c# .net vb.net datagridview