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
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.
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
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
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.
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