Event handler for multiple command buttons

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
 
D

David A. Beck

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)
 
C

Chris Jackson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top