0

I am new to programming. I need to get a list of ALL menuItems (ToolStripMenuItems) including Dropdown menuitems. I found some codes, but it list Main Menu Items only, No Dropdown menuItems. Can you give me a suitable code for list ALL menuItems.

    foreach (ToolStripMenuItem item in menuStrip.Items)
    {
         MessageBox.Show(item.Name);
    }
SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
Dilhan
  • 1
  • 1

1 Answers1

3

The child items have a DropDownItems collection.

Write a recursive function like this one:

private void print( ToolStripMenuItem element )
{
    MessageBox.Show(element.Name);

    foreach ( ToolStripMenuItem child in element.DropDownItems )
    { 
        print( child );
    }
}
The Scrum Meister
  • 29,681
  • 8
  • 66
  • 64
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291