Hi I am trying to find all mdi menu items and menu items child and there child. in mdi there is three level for menu.
now problem is I am able to find child upto second level, please help me to find the third level child. for example: Master->Station->domestic , I am able to search till station not domestic below is the code.
public void SecurityCheck(MDIColts ObjMdi)
{
Int32 Count;
if (Global.GetInstance.LoggedInUserType != "SA")
{
foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
if (colMenuItem.Contains(tsmi.Name) == true)
{
tsmi.Visible = true;
}
else
{
tsmi.Visible = false;
}
for (Count = 0; Count < tsmi.DropDownItems.Count; Count++)
{
if (colMenuItem.Contains(tsmi.DropDownItems[Count].Name) == true)
{
tsmi.DropDownItems[Count].Visible = true;
}
else
{
tsmi.DropDownItems[Count].Visible = false;
}
}
}
else
{
foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
tsmi.Visible = true;
for (Count = 0; Count < tsmi.DropDownItems.Count; Count++)
{
tsmi.DropDownItems[Count].Visible = true;
}
}
}
}
Loading
Nilanka DharmadasaPosted Jan 15, 2010, 12:20 AM
Hi Mahesh,
It's simple.
Use following code. You can go upto anylevel.
foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
if (colMenuItem.Contains(tsmi.Name) == true)
{
tsmi.Visible = true;
}
else
{
tsmi.Visible = false;
}
foreach (ToolStripMenuItem itemlevel1 in tsmi.DropDownItems)
{
if (colMenuItem.Contains(itemlevel1.Name) == true)
{
itemlevel1.Visible = true;
}
else
{
itemlevel1.Visible = false;
}
foreach (ToolStripMenuItem itemlevel2 in itemlevel1.DropDownItems)
{
if (colMenuItem.Contains(itemlevel2.Name) == true)
{
itemlevel2.Visible = true;
}
else
{
itemlevel2.Visible = false;
}
foreach (ToolStripMenuItem itemlevel3 in itemlevel2.DropDownItems)
{
//......Similarly you can go further down if you want.
}
}
}
}
If you find my answer helpful, please tick 'Do you like this answer' checkbox. It helps me.