“是否存在用于在选择鼠标指针时在DataGridView中查找列值之和的功能?”

时间:2019-08-20 08:22:08

标签: vb.net

通过将鼠标拖动到DataGridView中,可以立即计算出DataGridView中选定列的选定单元格值的总和。

我尝试了以下代码,但对我而言无效。

`Private Sub grid1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grid1.SelectionChanged

Try
        Dim sum As Double = 0
        For Each row As DataGridViewRow In grid1.SelectedRows
            sum += Convert.ToDouble(row.Cells("Item Rate").Value)
           Next
                       txtCr.TextboxValue = sum.ToString()
    Catch ex As Exception
    End Try
End Sub

1 个答案:

答案 0 :(得分:0)

非常感谢Jimi

 Private Sub grid1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles grid1.SelectionChanged
    Try
        Dim SUM As Double = 0
        For Each cell As DataGridViewCell In grid1.SelectedCells
            If cell.ColumnIndex() Then
                SUM += Convert.ToDouble(cell.Value)
            End If
        Next
        txtCr.TextboxValue = SUM.ToString()
    Catch ex As Exception
    End Try
End Sub

结束班级