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

Posts Tagged ‘windows form’

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)


Posted in C# | Tagged: , , , , | Leave a Comment »