Solved

Using a toolbar

Posted on 2004-10-22
249 Views
Last Modified: 2012-05-05
Using the code below it don't work for each button I have in my toolbar.  How can I use each of the buttons for something diffrent line I did with the menuitems?

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick

' Do something here

    End Sub
0
Question by:teamdad
    4 Comments
     
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    You can determine which button was clicked using code like this:

        Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
            Select Case ToolBar1.Buttons.IndexOf(e.Button)
                Case 0
                    MsgBox("First Button Clicked")

                Case 1
                    MsgBox("Second Button Clicked")

                Case 2
                    MsgBox("Third Button Clicked")

            End Select
        End Sub
    0
     
    LVL 8

    Accepted Solution

    by:
    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
            Select Case e.Button.Tag
                Case "NewRecord"
                    'Code to add new record

                Case "Save"
                    'Code to save record
            End Select
        End Sub
    0
     

    Author Comment

    by:teamdad

    For some reason this only fires the first button but not the second or third.

    Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
            Select Case ToolBar1.Buttons.IndexOf(e.Button)
                Case "1"
                    MsgBox("First Button Clicked")

                Case "2"
                    MsgBox("Second Button Clicked")

                Case "3"
                    MsgBox("Third Button Clicked")

            End Select
        End Sub
    0
     
    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Take off the quotes.  This:

        Case "1"

    should be:

        Case 1

    and it should be zero indexed.

    ~IM
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    931 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now