Solved

Click Event For ToolStrip Drop Down Button

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

751 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