curiouswebster
asked on
WinForms C#: I need to get a MenuStripItem from a MenuStrip variable
I have the MenuStrip and filled it with items using the designer. Now, from the code, I need to get a refernce to a given menu item.
How do I do this?
How do I do this?
ASKER
I need to get the item to enable/disable it. How do I do that?
The default name is the Text, with the first letter lower-case, followed by "ToolStripMenuItem".
So if the menu said "File" it would be:
fileToolStripMenuItem.Enab led = false;
So if the menu said "File" it would be:
fileToolStripMenuItem.Enab
ASKER
That's neat. But let's say I wanted to disable File > Save...
and that I do indeed know the Name of the corresponding ToolStripMenuItem.
and that I do indeed know the Name of the corresponding ToolStripMenuItem.
?
Have you tried?
saveToolStripMenuItem.Enab led = false;
Have you tried?
saveToolStripMenuItem.Enab
ASKER
Only the parent showed up with Intellisense.
ruleToolStripMenuItem
contains the "Add..." menu item
when I type "a", nothing shows up. Can I query ruleToolStripMenuItem to find a menu item with a given Name? That menu item belongs to ruleToolStripMenuItem.
ruleToolStripMenuItem
contains the "Add..." menu item
when I type "a", nothing shows up. Can I query ruleToolStripMenuItem to find a menu item with a given Name? That menu item belongs to ruleToolStripMenuItem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works fine for me, too. But I do not want to disable the whole menu, just one menu item.
That will only disable the "Add" menu item. Everything else would remain available...
Can you explain in more detail about your setup and what is actually happening?
Can you explain in more detail about your setup and what is actually happening?
ASKER
My bad. I see the items in Intellisense.
Thanks!
Thanks!
For example:
this.mnuFile.Text = "File";
Hope that helps.