日期:2014-05-19  浏览次数:20742 次

如何加總Datagridview中某個字段的值到主表的TextBox中?
如:
NO       QTY       PRICE       AMT
1         2           3               6
2         5           2               10
3         1           12             12
......


===============================
要將AMT字段的值(28)   加總後寫入到TextBox中



------解决方案--------------------
select sum(AMT) from table
------解决方案--------------------
int R1 =0;
int R2=0;
for (int i = 0; i < this.dataGridView1.Rows.Count-1; i++)
{
R1 = Convert.ToInt32(this.dataGridView1.Rows[i].Cells[3].Value);
R2+=R1;
}
this.textBox1.Text=R2.ToString();
------解决方案--------------------
sz709( "钱 "途越渺茫...,越要拼命学...) 写的可行,
如果使用的数据源有具体的datatable,对其列下的数据进行合计也是可行的 。