Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build Treeview from Database...

Status
Not open for further replies.

lidds

Programmer
Jun 9, 2005
72
GB
I am really stugling with this an was hoping that someone has done this in the past and can lend some guidance, I have had a look on Google but I only seem to find examples of one parent and one child.

Anyway back to the problem, I have a treeview on a form and I want to allow the user to create a tree structure of their choice. What I mean by that is no limit to parent and child combinations, so basically have the same functionality as in Window Explorer.

Now comes the problem, what I want to be able to do is store this tree view hierarchy in a database, so that when they add a new node to the treeview it is stored in the database at the correct level. Then if the user closes the form and re-opens it loads the treeview hierarchy from the database.

I would really apreshiate some guidance on database table stucture and how I can loop through and build the treeview

Thanks in advance

Simon
 

how i have done it is by using a recursive table setup.

node ID
parent node ID
node name
[more fields, if needed]

and as a result, you will have to use recursion to read from the table to programmatically build the tree structure. i don't have my code with me, but essentially you should re-use the procedure you write to cover the scenario of a node having child nodes and therefore traverse it and other subsequent child nodes in order to add content to a tree control

i re-used code i had written in ms access that used 2 function calls to do the job, which i ported to .net

when i get back, and if you want a code example, let me know

hope that helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top