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

Debug Stored Procedures (SPs) in Visual Studio .NET

Though I have heard of it I never wanted to try it till yesterday, the debugging a SP in Visual Studio .NET is a straight forward job as follows - Open your project - Add a New Connection to Visual Studio Select and open the respective SP and break point can be added then right click on the Stored Procedure in the Server Explorer, select Step into Stored Procedure "One more setting" – go to the project settings, Set Debuggers SQL Server true "Happy Debugging"

Close Parent window from nested iframe child pages : javascript;

for : IE and FireFox 1: <script language="javascript" type="text/javascript"> 2: function CloseAll() { 3: if (top === self) { 4: alert('not iframed'); 5: if (navigator.appName == "Microsoft Internet Explorer") { 6: self.close(); 7: } 8: else { 9: var respnseVal = confirm("Do you wan't to close this window"); 10: if (respnseVal) { 11: netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); 12: window.open('', '_self'); 13: window.close(); 14: } 15: } 16: } 17: else { 18: alert('iframed'); 19: if (navigator.appName == "Microsoft Internet Explorer") { 20: top.close(); 21: } 22: else { 23: var respnseVal = confirm("Do you w...