title: Dynamically Remove ToolStripMenuItems from MenuStrip with parent's C#
body: <p>Hello to all the community of stackoverflow, I came to you today to ask a help with a problem I'm trying for several days to fix.</p>
  
  <p>I need to find a recursive algorithm that is able to find the children, if not then have the parent (submodule) has to be removed/hidden.
  The Parent Objects have a tag called: submodule.
  Children objects have one called: moduleoption</p>
  
  <p>I have the following scenarios:</p>
  
  <pre><code>Main
    L Item (Tag: moduleoption)
    L SubMenu 2 (Tag: submodule)
        L Item (Tag: moduleoption)
        L Item (Tag: moduleoption)
        L SubMenu 2.1 (Tag: submodule)  &lt;-- Remove/Hide
    L SubMenu 3 (Tag: submodule) &lt;-- Remove/Hide
  </code></pre>
  
  <p>In this scenarios i want to hide: SubMenu 2.1, SubMenu 3, because they do not have children.</p>
  
  <p>--</p>
  
  <pre><code>Main &lt;-- All are empty submodules, Remove/Hide MenuStrip
    L SubMenu 1 (Tag: submodule) &lt;-- Remove/Hide
    L SubMenu 2 (Tag: submodule) &lt;-- Remove/Hide
    L SubMenu 3 (Tag: submodule) &lt;-- Remove/Hide
  </code></pre>
  
  <p>In this second case as all submodules are empty then it is not necessary to show menustrip Control.</p>
  
  <p>My Code:</p>
  
  <pre><code>private ToolStripMenuItem MenuStripHide(MenuStrip MenuS)
  {
  
              if (MenuS.HasDropDownItems)
              {
                  foreach (ToolStripMenuItem ToolStrip in MenuS.DropDownItems)
                  {
                      if (ToolStrip.HasDropDownItems == false)
                      {
                          ToolStrip.Visible = false;
                      }
  
                      //call recursively
                      GetSubMenuStripItems((ToolStripMenuItem)ToolStrip);
                  }
              }
              else
              {
                  MenuS.Visible = false;
              }
  
      return menuItem;
  }
  </code></pre>
  
  <p>It took days thinking around this, since advance thank you very much.</p>