Solved

VB.NET: Can I rewire button events to handle several different button clicks through one click event

Posted on 2010-09-21
8
451 Views
Last Modified: 2013-11-26
I have a form with 5 buttons that simply click through a datatable.  The buttons are FIRST, LAST, PREVIOUS, NEXT and NEW.  For the sake of discussion lets say the buttons are named btnFIRST, btnLAST, etc...
Instead of coding through 5 separate button events to call one subroutine (and pass the button object to the subroutine), is there a way that I can do an AddHandler or something to allow the one added event to handle  the clicks of any and all buttons?
0
Comment
Question by:LiebertUser
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 33727159
Sure...you can either:

    Use the "Handles" keyword and list MULTIPLE controls afterwards
    < or > 
    Wire them all up at run-time with AddHandler()

In either case, the "sender" parameter will tell you which button fired the event:
    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFIRST.Click, btnLAST.Click, btnPREVIOUS. Click, btnNEXT.Click, btnNEW.Click
        Dim SourceButton As Button = CType(sender, Button)
        ' ... do something with "SourceButton" ...
    End Sub

Open in new window

0
 
LVL 18

Assisted Solution

by:John (Yiannis) Toutountzoglou
John (Yiannis) Toutountzoglou earned 249 total points
ID: 33727174
select all your button ...Go to properties -Events and double click the click event...this add a button click event handling all the buttons...
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33727206
Ok i quit!!!!!@Idle's here!!!!! :):):)
0
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33727227
Lol...you gotta be fast around here!  ;)

I'm gonna go mow my lawn so I won't be around for awhile...have fun jtoutou!   =D
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33727242
u2!!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33727276
i do not know how fun is for you to mow the grass but i love it ....!!!
0
 

Author Comment

by:LiebertUser
ID: 33727285
First and foremost, both of your solutions are terrific because I had no cliue they existed.  I was aware of Addhandler(), and planned on wiring the events at run time... but if I did that, then anytime I clicked on one of the buttons in the GUI designer it would create a new solo event for me.

I didn't know about the multiple handles capability of HANDLES...  I added
Handles btnFIRST.Click, btnLAST.Click, btnPREVIOUS. Click, btnNEXT.Click, btnNEW.Click

Now when I click on any of the buttons the GU designer redirects me to the one event!!! It's perfect!  Thanks!!!
I'm splitting the points and getting out of here before a fight breaks out....  I got what I needed <grin>!

0
 

Author Comment

by:LiebertUser
ID: 33727318
I meant to close the question in my response ID 33727285.  I got in a hurry and clicked the wrong thing.  Anyway, close it, award the points, they answered it perfectly.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question