![](/img/trans.png)
[英]Converting a CollectionChanged event handler line from C# to VB.net
[英]How to handle DataGridView event CollectionChanged in VB.NET?
我想在我的winforms应用程序中处理一个简单DataGridView的CollectionChanged事件。 我可以使用以下代码使用C#进行处理:
this.datagridview.DataBindings.CollectionChanged += DataBindings_CollectionChanged;
但是如何使用VB.NET处理事件? 我无法通过以下方式访问代码内的DataBindings属性:
Private Sub handleCollectionChanged(sender As Object, e As EventArgs) Handles datagridview.DataBinding.CollectionChanged
' do something
End Sub
我尝试过
Private WithEvents dataBinding As System.Windows.Forms.ControlBindingsCollection
Public Sub New()
InitializeComponent()
dataBinding = RadGridView1.DataBindings
End Sub
但这也不起作用。
关于上面的评论:我发现我的示例正常工作,问题是另一个:仅在后面的数据绑定集合已更改的情况下引发CollectionChanged事件,而绑定数据的内容未更改。 要处理网格数据源上的更改,可以处理用于数据源的对象列表的ListChanged事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.