Solved

Click Event For ToolStrip Drop Down Button

Posted on 2010-08-28
3
2,697 Views
Last Modified: 2012-06-21
I have a form with a StatusStrip that includes a drop down that is dynamically populated at run time.   My problem is that I can't access the click event for the dynamically populated items at run time.  If I manually populate the items at design time VB creates a click event for each item in the drop list.  How can I create a routing that catches clicks on any drop item so that I can do processing at run time?  I also need to know which item was cliicked - i.e. the text that is displayed in the drop menu.


toolstripdrop.gif
0
Comment
Question by:DRRobinson
[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
  • 2
3 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33549885
"You need to handle a click event using AddHandler.  There are two ways
to do this.

You can add a handler for the Click event of each item you add to the
ToolStrip, or you can add a handler for the ToolStrip's ItemClicked
event.

In either case you can use a single handler routine, and use the
sender and event arguments to determine what was clicked."
http://www.eggheadcafe.com/software/aspnet/31732850/you-need-to-handle-a-click-event-using-addhandler.aspx
0
 

Author Comment

by:DRRobinson
ID: 33550111
OK.. I got the general idea of it, but not sure of the syntax, I want a single handler to handle all click events on the drop down items, I'm not sure of the addhandler syntax to capture clicks on drop down items, and not the parent statusstrip items:

[code]
        SQLConn.Open()
        SQLcmd = New SqlCommand("select * from tblpermits where [enddate] >= '" & DateSerial(TodaysDate.Year, (TodaysDate.Month), TodaysDate.Day) & "' order by permitno", SQLConn)
        SQLrdr = SQLcmd.ExecuteReader
        While SQLrdr.Read
            Me.StatusBarDrop.DropDownItems.Add(SQLrdr("permitno") & " -  " & SQLrdr("name"))
            If TotalActivePermits > 15 Then Me.StatusBarDrop.AutoSize = False
        End While
        AddHandler ToolStripMenuItem_Click, AddressOf StatusDropDownClick
'This doesn't work
        SQLrdr.Close()
        SQLcmd.Dispose()
[/code]

When I manually create a drop down item in design mode, VB adds the click event based on the name of the item added:

[code]
    Private Sub ToolItemToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolItemToolStripMenuItem.Click

    End Sub
[/code]
0
 

Accepted Solution

by:
DRRobinson earned 0 total points
ID: 33550763
FIgured it out... just need to use the existing event:

StatusBarDrop_DropDownItemClicked
0

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 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