我想检测特定列的单元格值已更改。
我的Datagridview名称是DGV_Products
6列。
Product ID | Descriptions | Quantity | Unit Price | Discount | Amount
G 01 | Gallon #01 | 2 | 1850 | 100 | 3600
G 02 | Gallon #02 | 1 | 1850 | 50 | 1800
我只想在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
*对英语不好的道歉。
哦,我找到了解决方案。我使用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
感谢您的时间。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句