是否可以在一行中添加所有单元格值并将结果放入Datagridview或listview中的另一列?如果是,请问如何在VB.net中进行此操作?
答案 0 :(得分:0)
这很简单。如果sum列是最后一列的代码:
Dim sumRowIndex As Integer = DataGridView1.ColumnCount - 1
Dim sum As Double = 0
For Each row In DataGridView1.Rows
For collumn = 0 To DataGridView1.ColumnCount - 2
'check if cell value is a number
If Double.TryParse(row.Cells(collumn).Value, Nothing) Then
sum = sum + row.Cells(collumn).Value
End If
Next
row.Cells(sumRowIndex).Value = sum
sum = 0
Next