anon271334
anon271334

Reputation:

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

Upvotes: 1

Views: 723

Answers (1)

xpda
xpda

Reputation: 15813

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

Upvotes: 1

Related Questions