Looks like you only have half of the curly braces showing, this would indicate that the break; command is being hit during every pass. Make sure you encapsulate the entire statement:
private void formm_display_function(string display_form_str)
{
foreach (ToolStripMenuItem menuItem in this.menuStrip1.Items)
{
if (menuItem.Text.Trim() == display_form_str)
{
menuItem.Visible = true;
break;
}
}
}
[EDIT]
ToolStripMenuItems
are derived from
ToolStripDropDownItem
, so if the menu items you are trying to compare against are in the same menu drop down (meaning they show vertically), then what you have is one
ToolStripMenuItem
containing the other
ToolStripMenuItems
. To access these, you need to iterate through the
ToolStripMenuItems
in the
DropDownItems
property.
private void formm_display_function(string display_form_str)
{
foreach (ToolStripMenuItem menuItem in this.menuStrip1.Items)
{
foreach(ToolStripMenuItem subitem in menuitem.DropDownItems)
{
if (subitem.Text.Trim() == display_form_str)
{
subitem.Visible = true;
break;
}
}
}
}
[/EDIT]