Form receiving notification of raised event in UserControl
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
精彩评论