Solved

Click Event For ToolStrip Drop Down Button

Posted on 2010-08-28
3
2,534 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
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

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 …
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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