I have a container form and a child window. The child window searches for the controls and updates the visibility status in database for that control. But after doing that I cannot close the child or parent window and it is throwing an exception unable to cast object of type 'System.Windows.Forms.ToolStripSeparator' to type 'System.Windows.Forms.ToolStripMenuItem'. I tried to catch the exception where the casting is done. But it is not showing the exception there. Please help
Below is the code for looping through menu.
for (int i = 0; i < toolStripItems.Count; i++)
{
ToolStripMenuItem mi = toolStripItems[i] as ToolStripMenuItem;
if (mi != null)
{
oldMenuToolTips.Add(mi.Name, mi.ToolTipText);
mi.ToolTipText = mi.Name;
if (mi.DropDownItems.Count > 0)
{
ShowToolStipItems(mi.DropDownItems);
}
PageControls.Items.Add(mi.Name);
}
}
I am trying the code from this tutorial https://www.simple-talk.com/dotnet/windows-forms/controls-based-security-in-a-windows-forms-application/