Hello everyone,
I am trying to create a dynamic menu user_control and I think the best way to go about this is with recursion. Recursion is where I get a bit lost so I hope someone can help me out. This is what I have:
1. I created a user control that has a list of a class I created.
2. This class has two properties : menuName and menuParent.
3. If the menu item is the root, then menuParent will equal "main, otherwise it will = the menuName of the the parent. For example:
menuName | menuParent
---------------------------------
menu 1 | main
menu 2 | main
sub men 1 | menu 1
sub men 2 | menu 1
ss men 1 | sub men 1
this list would represent two root menu items (menu 1 and menu 2). one of the roots (menu 1) has two sub menus (sub men 1 and sub men 2) and one of these sub menus (sub men 1) has one sub menu (ss men 1). It practice, there can be any number of menus all of which have any number of subs...and so on.
Assuming i have an object as specified above, how could I use recursion to create a debug.print that looks like this:
menu 1
sub men 1
sub men 2
sub men 1
menu 2
As I said, I will never know how many roots, subs, subs of subs, etc there will be, so i cant hard code anything. These objects can also be in any order. I would appreciate any help.
Thanks
jason


Reply With Quote