Jean Paul's Blog

There are 2 types of People in the World, One who Likes SharePoint and..

  • Microsoft MVP

  • MindCracker MVP

  • CodeProject MVP

  • eBook on SharePoint 2010

  • eBook on Design Patterns

  • eBook on Windows Azure

  • NLayers Framework @ CodePlex

  • MSDN Forums

  • .Net vs. Java

    Due to Public Demand

WinForms :: Get subitems in Menu programmatically

Posted by Jean Paul on November 11, 2011

This is a small piece of code to iterate over menu sub items dynamically. The topic was generated from a forum fix and I thought it will be a good idea to blog it.

/* Place a menu strip control with File and Edit as the top level items.  Inside the File menu add 3 subitems.  Those items can be viewed dynamically using the following code */


MenuStrip menuStrip = this.Controls.Cast<Control>().Where(c => (c is MenuStrip)).FirstOrDefault() as MenuStrip;
if (menuStrip != null)
ToolStripMenuItem menuItem = menuStrip.Items.Cast<ToolStripMenuItem>().Where(mi => mi.Text.Replace("&", string.Empty).ToLower() == "file").FirstOrDefault() as ToolStripMenuItem;
foreach (ToolStripItem item in menuItem.DropDown.Items)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s