Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:

I have a form which has a lot of ToolStripMenuItem that created by the designer and I want to assign a same event handler to them, how do I do that?

Here's my code
Private Sub AddEventClick(ByVal target As ToolStripItemCollection)
    For i As Integer = 0 To target.Count
        Dim ts As ToolStripMenuItem = target(i)
        If ts.HasDropDownItems Then AddEventClick(ts.DropDownItems)
        'Here I want to assign the event handler
End Sub
Private Sub toolStripDrawing()
    tsh = New TSHandler
    Dim target As ToolStripItemCollection = BuatObjekToolStripMenuItem.DropDownItems
End Sub

Any idea to do this? I really don't want to assign each event one by one (since it'll be too troublesome to update)

1 solution

Use AddHandler
AddHandler ts.Click, AddressOf ToolStripMenuItem_Click 'place the name of your function
Share this answer
Sergey Alexandrovich Kryukov 10-Jun-11 13:43pm    
Sure, a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900