|
-
August 25th, 2004, 02:13 PM
#1
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
-
August 25th, 2004, 03:13 PM
#2
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
-
August 25th, 2004, 03:28 PM
#3
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;
}
-
August 25th, 2004, 04:30 PM
#4
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
-
August 26th, 2004, 10:56 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|