CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    392

    Menustrip items count

    Dear All,
    How can I get the menustrip items count including the dropdown items

    Dana
    VS 2005

  2. #2
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    1,080

    Re: Menustrip items count

    A menu is a tree structure so recursion is the way to traverse it:
    Code:
    Private Function GetItemCount(ByVal menu As MenuStrip) As Integer
        Dim count As Integer = menu.Items.Count
    
        For Each item As ToolStripMenuItem In menu.Items
            count += Me.GetSubItemCount(item)
        Next item
    
        Return count
    End Function
    
    Private Function GetSubItemCount(ByVal item As ToolStripMenuItem) As Integer
        Dim count As Integer = item.DropDownItems.Count
    
        For Each subitem As ToolStripMenuItem In item.DropDownItems
            count += Me.GetSubItemCount(subitem)
        Next subitem
    
        Return count
    End Function
    Tutorials: Home & Learn | Start VB.NET | Learn VB.NET | C# Station | GotDotNet | Games in VB.NET 101 Samples: 2002 | 2003 | 2005 | More .NET 2.0 (VB.NET, C#) Articles: VB.NET | C# | ASP.NET | MoreFree Components: WFC | XPCC | ElementsEx | VBPP | Mentalis | ADO.NET/MySQL | VisualStyles | Charting (NPlot, ZedGraph) | iTextSharp (PDF) | SDF (CF) ● Free Literature: VB 2005 (eBook) | VB6 to VB.NET (eBook) | MSDN Magazine (CHM format) ● Bookmarks: MSDN | WinForms .NET | ASP.NET | WinForms FAQ | WebForms FAQ | GotDotNet | Code Project | DevBuzz (CF) ● Code Converter: C#/VB.NET | VB.NET/C# | VS 2005 add-in

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured