如何检测特定datagridview列的单元格值已更改?-VB.NET

Muh*_*qib 3 vb.net datagridview datagridviewcolumn

我想检测特定列的单元格值已更改。

我的Datagridview名称是DGV_Products6列。

Product ID | Descriptions | Quantity | Unit Price | Discount | Amount
G 01       |  Gallon #01  |    2     |   1850     |    100   |  3600 
G 02       |  Gallon #02  |    1     |   1850     |    50    |  1800
Run Code Online (Sandbox Code Playgroud)

我只想在Quantity column单元格值更改时触发一些代码,而在值更改时不触发discount column。我该如何完成任务?目前的代码,我尝试过的是;

 Private Sub DGV_Products_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV_Products.CellValueChanged

    If DGV_Products.Rows.Count > 0 Then

        Dim Quantity As Integer = CInt(DGV_Products.CurrentRow.Cells(2).Value)
        Dim UnitProce As Integer = CInt(DGV_Products.CurrentRow.Cells(3).Value)
        Dim DiscountPrice As Integer = CInt(DGV_Products.CurrentRow.Cells(4).Value)

        Dim TotalDiscount As Integer = DiscountPrice * Quantity
        Dim Amount As Integer = UnitProce * Quantity
        Amount = Amount - TotalDiscount

        DGV_Products.CurrentRow.Cells(4).Value = TotalDiscount
        DGV_Products.CurrentRow.Cells(5).Value = Amount


        RefreshTotal()

    End If
End Sub
Run Code Online (Sandbox Code Playgroud)

*对英语不好的道歉。

Muh*_*qib 5

哦,我找到了解决方案。我使用e.ColumnIndex财产,但问题解决了。

 If DGV_Products.Rows.Count > 0 Then

        If e.ColumnIndex = 2 Then
            Dim Quantity As Integer = CInt(DGV_Products.Rows(e.RowIndex).Cells(2).Value)
            Dim UnitPrice As Integer = CInt(DGV_Products.Rows(e.RowIndex).Cells(3).Value)
            Dim UnitDisocunt As Integer = GetDiscountByProductID(DGV_Products.Rows(e.RowIndex).Cells(0).Value)
            Dim TotalDiscount As Integer = UnitDisocunt * Quantity
            DGV_Products.Rows(e.RowIndex).Cells(4).Value = TotalDiscount
            Dim Ammount As Integer = UnitPrice * Quantity
            Ammount = Ammount - TotalDiscount
            DGV_Products.Rows(e.RowIndex).Cells(5).Value = Ammount
            RefreshTotal()
        End If

    End If
Run Code Online (Sandbox Code Playgroud)

感谢您的时间。