User control! how to access to an event

  • Thread starter Thread starter Marcos Beccar Varela
  • Start date Start date
M

Marcos Beccar Varela

Hello, I´m trying to access to an event of a listbox, thats inside an user
control. Whenever the listbox changes a value I need to rise an event. Is
there a way of doing this?


MyUserControl > 1 textbox
1 Listbox



MyForm > 1 MyUserControl

(here, in my Form, I need to control the event, when the listbox of
MyUserControl Changes a value.


Thank you all!
 
I think this will work in the main form on which the user control is placed;

Private sub myListBoxEvent (........parms for list box event...) handles
Me.MyUserControl.myListBox.MyEvent

end sub

Note that the instance of the listbox within the usercontrol has to be public.
 
Marcos Beccar Varela said:
Hello, I´m trying to access to an event of a listbox, thats inside an
user control.

Don't. You might want to, say, replace the ListBox with some
other control later on and, if you've exposed it directly, you'll
break all your existing client applications.

Duplicate the Event at the UserControl level and pipe-line the
Event from the ListBox to the Outside World, as in

Public Event SomeEvent( sender as Object, e as EventArgs )

Private Sub List1_SomeEvent( sender as Object, e as EventArgs )
RaiseEvent SomeEvent( sender, e )
' or, perhaps better
' RaiseEvent SomeEvent( Me, e )
End Sub

HTH,
Phill W.
 
Back
Top