472,334 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,334 software developers and data experts.

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 1323
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing...
2
by: Keith Smith | last post by:
Is there a way to attach event handler code to multiple controls?
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them,...
3
by: akki | last post by:
I create link buttons dynamically in the code and give them IDs through which I can distinguish them.I want to know how to create a single event...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the...
9
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will...
2
by: Bundy | last post by:
Hi On my webpages I have replaced the submit button with a rolling submit button using the script below (Script 1). This script is used by many...
2
by: =?Utf-8?B?TWlrZSBSYW5k?= | last post by:
I have created a method that dynamically creates a single button control (as a proof-of-concept, I would like to be able to create multiple...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.