Results 1 to 10 of 10

Thread: Saving TreeView Structure to DB

  1. #1

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677

    Saving TreeView Structure to DB

    Hello all. I have a program where users can build a TreeView via Drag and Drop from a DataGrid. This works perfect. Can someone give me some suggestions on how to save the TreeView Structure to a database? Thanks alot, Jeremy
    He who listens well, speaks well.

  2. #2
    Member
    Join Date
    Jun 2002
    Posts
    36
    You can use self referenced table. Unique ID for each node in a tree and Parent column for referencing. For example one node has ID=1 another one has ID=2. Node with ID=2 has a Parent=1 in Parent column which corresponds to node with ID=1. This reflects treeview structure.

  3. #3

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    I can do that similarly right now with the text from the nodes. My problem is this, the nodes don't show up in the same place that they were at when created. The parent/child structure is correct but the ordering isn't. Make sense? Thanks, Jeremy
    He who listens well, speaks well.

  4. #4
    Member
    Join Date
    Jun 2002
    Posts
    36
    What if you use Order By clause?

  5. #5

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    It wouldn't work. There is not specific sort by function that will do what I need. Besides, the tree is built by two separate tables. Everytime I drag a new node to a table structure, I have to insert a row into either the PS table or the RT table. (Depending on what's being dragged and dropped.) I could try to time stamp the rows in the database, join the two tables together to create one recordset and then sort by time stamp row but I wouldn't even know where to begin. Any ideas? Thanks, Jeremy
    He who listens well, speaks well.

  6. #6
    Member
    Join Date
    Jun 2002
    Posts
    36
    It's hard to suggest not knowing RT and PS structure and their
    relationship, but I can tell you based on my experience how I implemented treeview structure for Departments/Divisions in my project.
    I created a table with GroupID(automatically generated unique number) field and ParentID for relationship between nodes. Every time I created a new record GroupID was generated, so all nodes were always in right order because in SELECT statement I put ORDER BY GroupID. What nice about selfreferenced structure is that you can create nodes with any level deep, just put correspondent ParentID. I think if you have two tables you complicate your problem.

  7. #7

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    Ok...I FINALLY know how this is done by talking to the software developers of the software I'm using a portion of. I'll attach a .zip file of two pictures. One, you'll notice the TreeView is correct (ProfitKey.gif) and the other, you'll see what's happenning when I do it (MySoftware.gif). From the pictures, you'll be able to see that there are two different types of nodes, red (Processes 'RT Table') and blue (Materials 'PS Table'). From talking to the developers from Profit Key, they told me that the nodes are sorted depending on their "OP NUM". This would be PS_OP_NUM in the PS table and RT_OP_NUM in the RT table. I'll also have an Excel Spreadsheet in the zip file that gives you the RT and PS table information. Form there, you should see how and why the Profit Key software works and mine doesn't. Can you help me devise a way to build my TreeView properly? Thanks, Jeremy
    Attached Files Attached Files
    He who listens well, speaks well.

  8. #8
    Member
    Join Date
    Jun 2002
    Posts
    36
    I can't open your zip file. It gives me an error.

  9. #9

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    I'll reattach. I just downloaded it from the link and opened it, no problem. Let me know if you have more problems. Thanks, Jeremy
    He who listens well, speaks well.

  10. #10

    Thread Starter
    Fanatic Member JCScoobyRS's Avatar
    Join Date
    Oct 2002
    Location
    Some Mountain in Colorado
    Posts
    677
    Here you go. Later, Jeremy
    Attached Files Attached Files
    He who listens well, speaks well.

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