[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Using a toolbar

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
teamdad
Asked:
teamdad
  • 2
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
wguerramCommented:
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
 
teamdadAuthor Commented:

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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Take off the quotes.  This:

    Case "1"

should be:

    Case 1

and it should be zero indexed.

~IM
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now