Vb.net Windows窗体用户控件的属性更新时不更新

Vb.net Windows窗体用户控件的属性更新时不更新,vb.net,properties,user-controls,form-load,Vb.net,Properties,User Controls,Form Load,我已经在VisualBasic表单应用程序中创建了一个用户控件。它有一个名为ID的属性 Private intID As Integer Public Property ID() As Integer Get Return intID End Get Set(value As Integer) intID = value End Set End Property 在用户控件的加载方法中,我根据ID刷新用户控件中的组件 Priva

我已经在VisualBasic表单应用程序中创建了一个用户控件。它有一个名为ID的属性

Private intID As Integer

Public Property ID() As Integer
    Get
        Return intID
    End Get
    Set(value As Integer)
        intID = value
    End Set
End Property
在用户控件的加载方法中,我根据ID刷新用户控件中的组件

Private Sub UserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    UpdateUserControlFields() ' This Method uses ID within
End Sub
现在,我希望每当我在添加此用户控件的表单中执行某些操作时,都能使用正确的ID显示此控件。例如,我有一个DataGridView,每当选择更改时,我都要更新用户控件:

Private Sub MyDataGridView_SelectionChanged(sender As Object, e As EventArgs) Handles MyDataGridView.SelectionChanged
    If Not IsNothing(MyBindingSource.Current) Then
        UserControlONE.ID = MyBindingSource.Current("someID")
        UserControlONE.Refresh() ' Doesn't Work.
        UserControlONE.Update() ' Doesn't Work.
    End If
End Sub

问题是用户控件仅在第一次使用所选ID正确加载,而我似乎无法重新加载它的数据。这意味着如果属性ID的值更改,我不知道如何强制重新加载用户控件。它显示与加载的第一个ID相同的数据。任何帮助都将不胜感激

不要在控件加载事件中更新ID,而是在属性更改时更新它:

Private intID As Integer

Public Property ID() As Integer
    Get
        Return intID
    End Get
    Set(value As Integer)
        intID = value
        UpdateUserControlFields() ' This Method uses ID within
    End Set
End Property

“在控件第一次可见之前发生”“

是否确实多次更改ID。在这一行上设置一个断点
UserControlONE.ID=MyBindingSource.Current(“someID”)
,并检查它是否在每次您在网格中选择某个内容时都会中断是的,每次都会中断,并且ID设置正确。但不会发生的是,即使更新了用户控件的ID,用户控件也不再转到其加载方法。用户控件的load方法仅在第一次调用时才被调用。如果调用ResetBindings方法,它是否会更新会导致绑定到BindingSource的控件重新读取列表中的所有项并刷新其显示的值。ResetBindings没有为我这样做。