开发者

Form receiving notification of raised event in UserControl

开发者 https://www.devze.com 2023-02-12 17:24 出处:网络
I still can\'t find anything on this. But in my app I have a main form (Form1) and inside that form is a UserControl. When a person clicks on an item in the ListView of开发者_如何转开发 that usercontr

I still can't find anything on this. But in my app I have a main form (Form1) and inside that form is a UserControl. When a person clicks on an item in the ListView of开发者_如何转开发 that usercontrol, I want to know about it (ItemSelectionChanged Event) inside the Form1 form. Any suggestions/advice on this?

Thank you


Inside usercontrol, define an event, such as

Event listviewItemChanged(ByVal itemIndex as integer)

Then, in the Listview ItemSelectionChanged event inside usercontrol, raise the usercontrol's listviewItemChanged event:

Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
RaiseEvent listviewItemChanged(e.ItemIndex)
End Sub

And finally, in Form1, handle the usercontrol.listviewItemchanged event:

Public Sub usercontrol_listviewItemChanged(ByVal itemIndex as Integer) Handles usercontrol.listviewItemChanged
...
end sub
0

精彩评论

暂无评论...
验证码 换一张
取 消