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...

How to use Laptop / Notebook Battery

I found a news that might help most of laptop owners to get an idea about their Laptop/Notebook battery life related things. news item describes things like, Battery Basics, How to check your battery, Best Practices and more. " Best practices to maintain battery life You'd think that the best way to keep your laptop's battery from wearing out is to not use it. Right? As it turns out, batteries are like muscles; they need to be worked out regularly to stay healthy. Ideally, you'd use your laptop unplugged at least once a day, like on a train or bus commute or on the couch in front of the TV. If you're not going to use it, constantly charging your battery is a bad idea; HP recommends on their website that if you're going to leave your laptop plugged in or put up in storage for more than two weeks, you should take the battery out of your laptop." source : yahoo.com