for (int i = 0; i < this.menuStrip1.Items.Count; i++)
{
//main menus items
string mnuItemName = this.menuStrip1.Items[i].Name;
ToolStripMenuItem tmpMenuItem = this.menuStrip1.Items[i] as ToolStripMenuItem;
//check for sub menu
for (int j = 0; j < tmpMenuItem.DropDownItems.Count; j++)
{
string menuSubItem = tmpMenuItem.DropDownItems[j].Name;
}
}
{
//main menus items
string mnuItemName = this.menuStrip1.Items[i].Name;
ToolStripMenuItem tmpMenuItem = this.menuStrip1.Items[i] as ToolStripMenuItem;
//check for sub menu
for (int j = 0; j < tmpMenuItem.DropDownItems.Count; j++)
{
string menuSubItem = tmpMenuItem.DropDownItems[j].Name;
}
}
Comments
What you have posted here is almost what I need...
I am new to C# and don't know how to retrieve details of menu items of a multi-level menu structure in my application...
When I saw your post I thought maybe you could expand your code to check for a multi-level menu...
My menu structure is as follows:
1. Root
1.1 File
1.1.1 Save
1.1.2 Export
1.1.3 Exit
1.2 Tools
1.2.1 Support
1.2.1.1 Bank
1.2.1.2 Currency
1.2.1.3 ------
1.2.1.4 Ref Table
1.2.1.4.1 Payment Method
1.2.1.5 Notifications
1.2.1.5.1 Bank
1.2.1.5.1.1 CitiBank
1.2.1.5.1.2 Bank of America
1.2.1.5.2 Credit Union
1.3 Help
1.3.1 View Help
1.3.2 -------
1.3.3 About
If you could expand your code to make it more generic (I mean, independent of how many submenus the application has, would you be able to send it to me at ctomazz@gmail.com???
I need to iterate through the menu structure and find out from my app's Permissions table what menu items the user is authorised to access... For those menu items the user cannot access, I need to set them enabled = false.
I truly appreciate any assistance you can give...
Thanks in advance...
Carlos