How to find toolstripmenuItem with name

Learner picture Learner · Sep 24, 2013 · Viewed 20.4k times · Source

I have set visible property of my menuStrip1 items to false as

foreach (ToolStripMenuItem itm in menuStrip1.Items)
{
    itm.Visible = false;
}

Now I know the Names of toolStripMenuItem and dropDownItem of the menustrip1. How to can I activate the required toolStripMenuItem and dropDownItem.

I have

string mnItm = "SalesToolStripMenuItem";
string ddItm = "invoiceToolStripMenuItem";

Now I want to set visible true to these two(toolStripMenuItem and dropDownItem) items. How can I do that? I know those names only.

Answer

King King picture King King · Sep 24, 2013

Simply use those names to get the actual item via MenuStrip.Items indexer:

ToolStripMenuItem menuItem = menuStrip1.Items[mnItm] as ToolStripMenuItem;
ToolStripDropDownMenu ddItem = menuStrip1.Items[ddItm] as ToolStripDropDownMenu;