There's a toolstripmenuitem in my Windows form Application. I need to access every sub menu items and check whether there is a specific menu item name is available and if that item found, I want to disable it. Eg:
Report
|__Stock
| |__Stock Balance
| |__Stock Reorder
|__Sales
|__Summary
My code is like this. According to my code, I can access sub menu(Stock) and disable it. But I'm unable to access child items(Stock Balance) inside sub menu.
String specificMenuItemName = "Stock Balance";
foreach (ToolStripMenuItem menuItem in MainMenuStrip.Items)
{
if (menuItem != null)
{
if (menuItem.HasDropDownItems)
{
foreach (ToolStripItem subMenuItem in menuItem.DropDownItems)
{
if (subMenuItem is ToolStripSeparator)
{ }
else
{
if (specificMenuItemName == subMenuItem.Text)
{
subMenuItem.Enabled = false;
}
}
}
}
}
}
How do I access to Stock Balance and disable it?