Skip to main content

C# Windows, Iterate through Menu Items (MenuStrip)

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;
}
}

Comments

Carlos said…
Hi Anuradha,

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

Popular posts from this blog

Enable Apache in XAMPP at Windows 7

1. Problem detected! Port 80 in use by "Unable to open process" with PID 4! Apache WILL NOT start without the configured ports free! You need to uninstall/disable/reconfigure the blocking application or reconfigure Apache and the Control Panel to listen on a different port 2. Error: Apache shutdown unexpectedly. This may be due to a blocked port, missing dependencies, improper privileges, a crash, or a shutdown by another method. Press the Logs button to view error logs and check the Windows Event Viewer for more clues If you need more help, copy and post this entire log window on the forums If you have come across either one of errors, mostly issue could be port 80 is used by another service or combination of services or a tool. If you are not a developer, you don’t have development software installed and Skype is installed; first go to  “Tools-> Option -> advanced -> connection” and check port 80 is used there? For developer it’s quite impressive (if the

FckEditor panels hide behind the Model Popup

Using FckEditor with asp.net model popup, there a possibility of Property windows hide behind the model popup panel change the configuration value to higher value than existing fckconfig.js and find this line: FCKConfig.FloatingPanelsZIndex = 100005 ; // 100005 value can be changed according to the browser : These z-index values can be checked using Element inspection facility of Firebug or IE developer Tool Bar, by applying appropriate values for respective panels (using styles) is another workaround