H all,
I created a menu strip in Winform not dynamically. And it's all in invisible, when the user is have rights only it visible. My one of username have full rights,. For this I wrote the below code,..
private void menuActive(MenuStrip menus)
{
foreach (ToolStripMenuItem menu in menus.Items)
{
menu.Visible = true;
for (int i = 0; i < menu.DropDown.Items.Count; i++)
{
menu.DropDown.Items[i].Visible = true;
}
}
}
But this is visible the menuItem and child menuItem,. my few childItem menu have more childItem. That means, In TsmMaster and tsmregisterMaster are visible but I can't access the registerMasters Childs(ClassMaster, division Master....)
See the below image,..
Please give your suggestion.
Try it with recursion:
private void ActivateMenus(ToolStripItemCollection items)
{
foreach (ToolStripMenuItem item in items)
{
item.Visible = true;
ActivateMenus(item.DropDown.Items);
}
}
Fixed version of Your code
private void menuActive(MenuStrip menus)
{
foreach (ToolStripMenuItem menu in menus.Items)
{
activateItems(menu);
}
}
private void activateItems(ToolStripMenuItem item)
{
item.Visible = true;
for (int i = 0; i < item.DropDown.Items.Count; i++)
{
ToolStripItem subItem = item.DropDown.Items[i];
subItem.Visible = true;
if (item is ToolStripMenuItem)
{
activateItems(subItem as ToolStripMenuItem);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With