Vb.net 选定行数据网格和单元格
我有Vb.net 选定行数据网格和单元格,vb.net,Vb.net,我有gridview用于发票需求和单元格 Number Description Price Qty Total Discount Grand Total 5050 Screen 50 1 50 5 45 6060 Case 100 2 200 50 150 当我更改价格、数
gridview
用于发票需求和单元格
Number Description Price Qty Total Discount Grand Total
5050 Screen 50 1 50 5 45
6060 Case 100 2 200 50 150
当我更改
价格
、数量
或折扣
的值时,我需要它来动态计算总计和总计。我做了一个小例子来说明您的需求(),因此:
- 使用属性,以便数据绑定可以正确使用代码
Private _description As String Public Property Description() As String Get Return Me._description End Get Set(ByVal value As String) If Not (value = Me._description) Then Me._description = value Me.NotifyPropertyChanged() End If End Set End Property
- 用于更新表单和其他结构
Public MustInherit Class BusinessObject Implements INotifyPropertyChanged Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged Protected Sub NotifyPropertyChanged(<CallerMemberName()> Optional ByVal propertyName As String = Nothing) RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName)) End Sub End Class
- 向表单对象添加数据绑定
Me._binding = New BindingSource() Me._binding.DataSource = New Shop() Me._binding.DataMember = "ShopItems" Me.ShopItemsDataGridView.DataSource = Me._binding Me.ShopItemsDataGridView.AutoGenerateColumns = True
如果您需要更多信息,请在谷歌上搜索WinForms数据绑定或类似功能。很抱歉,当我更改任何值total=price*qtygrand total=total折扣时,我希望每个单元格都能更新
Me._binding = New BindingSource()
Me._binding.DataSource = New Shop()
Me._binding.DataMember = "ShopItems"
Me.ShopItemsDataGridView.DataSource = Me._binding
Me.ShopItemsDataGridView.AutoGenerateColumns = True