我有 3 个 vb.net 形式的 Datagridview 控件。DGV1 带有价格栏,DGV2 带有数量栏,第三个是总栏 DGV3。任何人都请告诉我如何执行此操作,DGV1*DGV2 在 DGV3 上显示总数,并在每次 DVG1 单元格值更改时更新 DGV3。我下面的代码不会更新 DGV3。此外,问题之一是 DGV3 在 DGV2 绑定 DATA 之前计算,如果 DGV2 单元格值 = 0,它会给我一个错误的总数。任何想法 ?赞赏,
Private Sub DGV1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV1.CellValueChanged
Dim Tot As Int32 = 0
DGV3.Enabled = False
DGV3.DataSource = Nothing
DGV3.Enabled = True
Dim OBJ As Double
Dim SALES As Integer
Dim dtt As DataTable
For Each R As DataGridViewRow In Me.DGV1.Rows
For Each N As DataGridViewRow In Me.DGV2.Rows
OBJ = CDbl(R.Cells(4).Value)
SALES = CInt(CDbl(N.Cells(0).Value))
Tot = CInt(OBJ * SALES)
DGV3.Rows.Add(Tot.ToString)
Next
Next
End Sub