如何在datagridview c#中的两行值之和

时间:2014-07-17 10:04:36

标签: c# .net vb.net

如果两个行的id相同并且在DataGrid中创建一行而不是两行,如何将DataGridView中的两行值相加?

如以下示例所示:

id           quantity       Bonus        price           total

01             25           10           123            4305

01             5             10          123            1845


I want to sum of the above two rows like this in the DataGrid.


id           quantity        Bonus         price          total

01              30            20             246          6150

如果我对它进行循环,则在datagridview中重复插入值。

1 个答案:

答案 0 :(得分:0)

考虑'网格'是网格的名称:

dim a(3) as integer
for i as integer =0 to grid.rows.count-1
for j as integer =0 to 3
a(j)=a(j)+ cint(grid.rows(i).cells(j).value)
next
next
grid.rows.add("Total",a(0),a(1),a(2),a(3)) ' will add a row at the end of last row