Link to home
Start Free TrialLog in
Avatar of curiouswebster
curiouswebsterFlag for United States of America

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?
Avatar of Luis Pérez
Luis Pérez
Flag of Spain image

Have you tried this.menuName?

For example:
this.mnuFile.Text = "File";

Hope that helps.
Avatar of curiouswebster

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.Enabled = false;
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.
?

Have you tried?

    saveToolStripMenuItem.Enabled = false;
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.
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
My bad.  I see the items in Intellisense.

Thanks!