如果两个行的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中重复插入值。
答案 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