Results 1 to 15 of 15

Thread: Recursion - so simple [but my head fails]

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    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.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

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