0

是否可以沿一行添加所有单元格值并将结果放在 Datagridview 或 listview 的另一列中?如果是,请问我该如何在 VB.net 中进行处理?

4

1 回答 1

0

这是相当直截了当的。如果总和列是最后一列,则代码:

    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
于 2013-04-09T17:47:42.503 回答