469,343 Members | 5,614 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,343 developers. It's quick & easy.

Event handler for multiple command buttons

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
Nov 18 '05 #1
2 1260
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)

"David A. Beck" <da****@beckb.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #2
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"David A. Beck" <da****@beckb.com> wrote in message
news:eX**************@TK2MSFTNGP09.phx.gbl...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by tony kulik | last post: by
18 posts views Thread by Christopher W. Douglas | last post: by
2 posts views Thread by Keith Smith | last post: by
6 posts views Thread by Steve Caliendo | last post: by
9 posts views Thread by jeff | last post: by
2 posts views Thread by =?Utf-8?B?TWlrZSBSYW5k?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.