|
-
Aug 23rd, 2012, 02:38 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Help with recursion
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
if i was able to help, rate my post!
-
Aug 23rd, 2012, 04:02 PM
#2
Lively Member
Re: Help with recursion
Last time I did something like this I serialized the data to XML and built the menu from that, infact you can use the built in menu in VS if you serialize to XML. Sorry if its not answering your question directly but last time I did anything with recursion I did it with recursion
**edit** http://msdn.microsoft.com/en-us/libr...atemplate.aspx HierachialDataTemplates are your friend for things like this!
**edit2** Recursive filtering using linq to objects, this may be easier for you:
http://stackoverflow.com/questions/1...inq-to-objects
Last edited by Joshwah!; Aug 23rd, 2012 at 04:12 PM.
-
Aug 24th, 2012, 07:57 AM
#3
Thread Starter
Hyperactive Member
Re: Help with recursion
Thanks for looking at this. I ended up finding the asp menu control that uses a sitemape to create a dynamic menu. I do have some questions about that but will post in a new thread. thanks again
jason
if i was able to help, rate my post!
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
|