CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2004
    Posts
    14

    Question All menuitems count?

    hello

    is there any way i can get the count of all the menuitems in the mainmenu withouth using recursion is there a property i havent seen or anythin else?

    thanks

  2. #2
    Join Date
    Oct 1999
    Location
    Colorado
    Posts
    288

    Re: All menuitems count?

    For main menu items
    PHP Code:
    MainMenu1.MenuItems.Count 
    For items in a paricular menu
    PHP Code:
    MainMenu1.MenuItems[0].MenuItems.Count 

  3. #3
    Join Date
    Aug 2004
    Posts
    14

    Question Re: All menuitems count?

    thanks but im talking about counting all the menuitems even the submenuitems and every menuitem menuitems

    i can do it with recursion but i wanna know if theres an easyer way

    here is the code

    private int iMenuItemCount = 0;

    private int GetAllMenuItemsCount(Menu comunalMenu)
    {
    foreach(menuitems menuItem in comunalMenu.MenuItems)
    {
    iMenuItemCount++;
    if(menuItem.IsParent)
    {
    iMenuItemCount+=menuItem.MenuItems.Count;
    this.GetMenuItemsCount(menuItem);
    }
    else
    return iMenuItemCount;
    }
    return iMenuItemCount;
    }

    private void GetMenuItemsCount(Menu comunalMenu)
    {
    foreach(menuitems menuItem in comunalMenu.MenuItems)
    {
    if(menuItem.IsParent)
    {
    iMenuItemCount+=menuItem.MenuItems.Count;
    this.GetMenuItemsCount(menuItem);
    }
    }
    return;
    }

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890

    Re: All menuitems count?

    if you know how many levels of menus you are already going to have then it would be possible without recursion, running 2-3 loops (depending upon nested menus)

    otherwise your recursive solution seems okay ..
    - Software Architect

  5. #5
    Join Date
    Aug 2004
    Posts
    14

    Smile Re: All menuitems count?

    i made a better recursion method after 1 day

    private int iMenuItemCount = 0;
    private int GetMenuItemCount(Menu comunalMenu)
    {
    try
    {
    foreach(menuitems comunalItem in comunalMenu.MenuItems)
    {
    iMenuItemCount++;
    if(comunalItem.IsParent)
    this.GetMenuItemCount(comunalItem);
    }

    return iMenuItemCount;

    }
    catch(Exception ex)
    {
    throw new Exception(ex.Message);
    }
    }

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