0

在此处输入图像描述

我创建了一个用于制作账单的 datagridview。现在我想添加所有第 4 列的值。我怎样才能做到这一点?

4

1 回答 1

0
 Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
        If e.ColumnIndex = 1 Then  // here your columnindex
            calctotal()
        End If
    End Sub
    Private Sub calctotal()
        Dim tot As Single
        For Each rw As DataGridViewRow In DataGridView1.Rows
            If rw.Cells(0).Value <> "" Then
                If String.IsNullOrEmpty(tot) Then
                    tot = Val(rw.Cells(0).Value) * Val(rw.Cells(1).Value)
                Else
                    tot = tot + Val(rw.Cells(0).Value) * Val(rw.Cells(1).Value)
                End If
                Label1.Text = tot
            End If
        Next
    End Sub
于 2013-08-24T11:23:57.537 回答