Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Click Event For ToolStrip Drop Down Button

Posted on 2010-08-28
3
Medium Priority
?
2,765 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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

705 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