Solved

Click Event For ToolStrip Drop Down Button

Posted on 2010-08-28
3
2,463 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
  • 2
3 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
"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
Comment Utility
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
Comment Utility
FIgured it out... just need to use the existing event:

StatusBarDrop_DropDownItemClicked
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

22 Experts available now in Live!

Get 1:1 Help Now