gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 12:25:55 26 4
gpt4 key购买 nike

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

我的 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属性(property),我的问题已经解决。

 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

感谢您的时间。

关于vb.net - 如何检测特定 datagridview 列的单元格值更改? - VB.NET,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25020381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com