C# retrieving MenuItems names...

EFileTahi-A

Contributor
Joined
Aug 8, 2004
Messages
623
Location
Portugal / Barreiro
Is is possible to retrieve the menu items names?

I can make it list the Menu items .Text:

Code:
foreach (System.Windows.Forms.MenuItem cCtrl in mainMenu.mainMenu1.MenuItems)
	{
		foreach (System.Windows.Forms.MenuItem cCtrlSub in cCtrl.MenuItems)
			{
				MessageBox.Show(cCtrlSub.Text.ToString());
			}
	}

Unfortunatey the System.Windows.Forms.MenuItem does not have the ".Name" propperty...

Is there any other way to make a loop where i can get a list of all menuItems names?
 
Why would you need the Name of the menus? Menuitems do not carry names around like controls do, and they're pretty much like an integer or a string... they don't carry a name.
If you need to reference a control, use the reference to the control. Don't try to do something overly complicated with the name of the menu. :)
 
Iceplug said:
Why would you need the Name of the menus? Menuitems do not carry names around like controls do, and they're pretty much like an integer or a string... they don't carry a name.
If you need to reference a control, use the reference to the control. Don't try to do something overly complicated with the name of the menu. :)

Imagine a button control...
The point to get the control.name is that u can modify its control.text and perserving the control name, so if I point to a control.name it will always be "ok" no matter how many changes its .text property suffers... The hole thing was to put into the database all menuitems (.name) in fields true / false, so that I could choose wich menuitems would be enabled / disabled, Visible (true, false). Yet, the program would automaticaly add a colunm into the database if a new menu would be add to the program, by using only the text reference, everytime I rename the menuItem.text, a column will be add into the database, whitch I dont wan't!. (there is not even the tag property which could do the same job .name would do)...
 
Back
Top