|
-
Jan 10th, 2013, 04:42 PM
#1
Thread Starter
PowerPoster
Recursion - so simple [but my head fails]
So I have this schema in the DB:
ID (PK, int)
ParentID (nullable int)
MenuName
I can select all records and thats great - populates an object for me with the above details (no SQL modification suggestions please)
I want to be able to recursively go through the list of these items and be able to add sub menu items to the parent menu items. For example:
ID ParentID MenuName
1, NULL, "File"
2, 1, "Open"
3, 1, "Save"
4, 1, "Save As",
5, 1, "Export"
6, 5, "To PDF"
7, 5, "To Docx"
8, 1, "Exit"
As you can see, menuID's from 2 to 5 and 8 belong to "file". These are submenus
Then we have menuID's 6 and 7 that belong to MenuID 5, which belong to MenuID 1
Currently I have all the items in a List<MenuItem>
This can change though where a 1 level submenu could become 2 levels...or x levels
I want to be able to add sub menus to parents.
makes sense?
Last edited by Techno; Jan 10th, 2013 at 04:50 PM.
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
|