|
-
Mar 13th, 2004, 11:28 PM
#1
Thread Starter
New Member
Populating treeview from database/structure
Hi, I am new to these forums, first time post. I usually struggle through a problem until I figure out the solution, but I am stumped.
I have a table in an access database with the following fields.
ID:
ParentID:
Name:
So, I might have the following data:
ID|ParentID|Name
1, 1, Parent1
2, 1, Child1
3, 3, Parent2
4, 2, Grandchild1
As you can probably guess, ID is a unique autoincrementing number, while parent ID is the ID of the record that is the parent of the current record.
In the treeview, I want to be able to take that info, and generate the treeview as such.
A treeview from the above sample table would like simliar to the following:
- Parent1
- Child1
- GrandChild1
- Parent2
The reason why I titled this post database/structure is because each seperate record in the database is loaded into a new instance of a class which contains properties for each of the fields (name, id, parentid), and each of those instances of the class are loaded into the hashtable, the key being the ID, and the value being the instance of the class. (may just change it to a structure later, but for now a simple class meets my needs, and is upgradeable in the future to hold some subs or functions if needed).
It's easy to populate the tree with the Parents, I just check to see if ID = ParentID, after that I need to check the ParentID's to the tag value of each node in the tree (which I made = to the ID of the record), and if so, then add a node under that node. I have came very close, and actually got it all working as long as there are no grandchildren or deeper (greatgrandchildren?).
If anyone can give me some tips on how to make this work, I would be greatly appreciative. I have been stuck on this for a couple of weeks and all other programming has halted until I can get passed this hurdle. Thanks.
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
|