title: C# Winforms Dynamic menu entries
body: <p>I'm attempting to create a dynamic menu strip in my program.  Here's an example of what it looks like right now:</p>
  
  <p><img src="https://img.photobucket.com/albums/v645/james_holly/menubar_zpsa33ffced.png" alt="Image"></p>
  
  <p>Creating the <code>ToolstripMenuItems</code> dynamically itself is easy.  What I plan to do is to check if the current month already exists in the folder paths that my program works with, and if it doesn't then it will create an extra menu strip with the date (for example once we hit August, it should create August 2014, with sub-items "NL" &amp; "PL").</p>
  
  <p>However the part that i am stuck at is how to link functionality to these dynamically created sub-items. As I've been unable to find a way to do this, both the "NL" and "PL" tabs open a specific .TXT file of that specific month (which is created elsewhere in the program). However when I make them dynamically, I can't find a way to make them do this and they just don't have any functionality.</p>
  
  <p>At this point I find myself manually creating new menu items &amp; code every month for this. And I would very much prefer the program to run itself.</p>
  
  <p>Any tips on how to make dynamic menuitems functional?</p>
  
  <p>Added code:</p>
  
  <pre><code>    private void CreateMenu()
      {
          ToolStripMenuItem item = new ToolStripMenuItem();
          item.Text = "Logs";
          DirectoryInfo dir = new DirectoryInfo(@"Y:\Heineken\Tools\Logs\");
  
          foreach (DirectoryInfo directory in dir.GetDirectories())
          {
              ToolStripMenuItem dateItem = new ToolStripMenuItem(directory.Name);
              ToolStripMenuItem NLMenu = new ToolStripMenuItem("NL"); // &lt;--- This needs to open a specific text file on a network share
              ToolStripMenuItem PLMenu = new ToolStripMenuItem("PL"); // &lt;--- This needs to open a specific text file on a network share
              dateItem.DropDownItems.Add(NLMenu);
              dateItem.DropDownItems.Add(PLMenu);
              item.DropDownItems.Add(dateItem);
          }
          menuToolStripMenuItem.DropDownItems.Add(item);
  
      }
  </code></pre>