Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I reference the menu item I added at run-time?
Message
General information
Forum:
ASP.NET
Category:
Menus
Miscellaneous
Thread ID:
00980910
Message ID:
00980989
Views:
54
Dawa,
Yes I know I can reference the menu item using it's index.
I already have the following code using a foreach:
foreach(System.Windows.Forms.MenuItem  oMI in this.mnuNetworkAdapters.MenuItems)
{
	oMI.Checked = false;
}
which I could convert to a for loop like this:
for (int i = 0 ; i < this.mnuNetworkAdapters.MenuItems.Count ; i++)
{
	this.mnuNetworkAdapters.MenuItems[i].Checked = false;
}
But this is the problem I have to loop though all the menu items in the particular "branch" and compare the Text property unless I know what order I put them in. In my case I have a collection of NetworkAdapter objects, which is what I use to populate the menu items so based on the "index" of the checked menu item I can reference the object in my collection of network adapters.

If I add a menu item through the designer I can change the Name property in the property sheet, let us say I change the Name property to mnuNewItem. Then if I switch to code I can reference that particular menu item but using this.mnuNewItem.Checked = true or something like that.

Einar



>I think your error is coming from ["Einar_0"], use [1] instead -- an integer value, then you'll be able to get a reference to the menu item as long as the refered exists.
Semper ubi sub ubi.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform