Event handler for multiple command buttons

  • Thread starter Thread starter David A. Beck
  • Start date Start date
D

David A. Beck

I would to set up a event routine for several command buttons. I need to be
able to identify by the caption or something whick button caused the event
to trigger. I think it's in the "sender" or "e" objects.
Private Sub cbOWN2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbOWN2.Click, cbOWN3,Click

IF sender.caption = "cbOWN2" THEN bla bla bla ELSE yatta yatta

End Sub
 
I figured it out. Use the CommandName and OnCommand attributes and then
define the function like so
e.CommandName then is the CommandName attribute of the button clicked
Public Sub cbIPID_click(ByVal sender As Object, ByVal e As CommandEventArgs)
 
The sender is the object that triggered the event. Since it is passed in as
an object variable, you will need to cast it to the appropriate type and
then invoke the methods or properties you need in order to uniquely identify
who broadcast the event.
 
Back
Top