Reputation: 685
I have a Tool Strip Menu with an entry named "General". When the form is loaded sub items are added to the "General" entry which are the result of reading the file names of text files in a folder.
I want to be able to capture the names of the sub items and add them to a label in the generic form which is called from clicking on the sub item.
I've tried using MsgBox(DirectCast(sender, ToolStripMenuItem).Text)
in an attempt to capture the text initially, however, it just gives me the "General" menu item in the messagebox
I am currently using this code in the DropDownItemClicked
event
Any ideas?
Upvotes: 1
Views: 3403
Reputation: 15813
The submenu items are in the collection ToolStripMenuItem.DropDownItems. You can cycle through the collection and select the ToolStripMenuItems. Not every item in the menu is a ToolStripMenuItem (there are separators, buttons, etc.), so you can cycle through with a ToolStripItem.
This example puts all the submenu items in a message box:
Private Sub mnuDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuDraw.Click
Dim s As String = ""
For Each item As ToolStripItem In sender.DropDownItems
If TypeOf (item) Is ToolStripMenuItem Then s &= item.Text & vbCrLf
Next item
MsgBox(s)
End Sub
Upvotes: 1