MenuStrip

  • Thread starter Thread starter Brian
  • Start date Start date
B

Brian

Hi,
I have a menustrip that has 3 main menus and various number of menus below
them...
I am trying to figure out how i can loop through the main menus and then
loop through each one of the main menus to get their items and .text field.
Any help....
Brian
 
Hi,
I have a menustrip that has 3 main menus and various number of menus below
them...
I am trying to figure out how i can loop through the main menus and then
loop through each one of the main menus to get their items and .text field.
Any help....
Brian

For example you have a MenuStrip1 and loop through items to get all
the item names as follows:

For x As Integer = 0 To MenuStrip1.Items.Count - 1
MsgBox(MenuStrip1.Items(x).Text)
Next

' ..Do the same iteration for other MenuStrip2 and 3...

Hope this helps,

Onur Güzel
 
This works for me.

Dim mStrip As MenuStrip = ctl (ctl comes from the whole control collection
over
which I am iterating)
Dim mItem As ToolStripMenuItem
Dim mSubItem As ToolStripMenuItem
Dim i As Int16, j As Int16, k As Int16

For i = 0 To mStrip.Items.Count - 1
mItem = CType(mStrip.Items.Item(i), ToolStripMenuItem)
MsgBox(mItem.Text)
' now look for sub menu items
For j = 0 To mItem.DropDownItems.Count - 1
MsgBox(mItem.DropDownItems(j).Text)
' now look for sub sub menu items (thats as far as we go)
mSubItem = mItem.DropDownItems(j)
For k = 0 To mSubItem.DropDownItems.Count - 1
MsgBox(mSubItem.DropDownItems(k).Text)
Next k
Next j
Next i
 
Back
Top