Populating TreeView from database

torisch

Newcomer
Joined
Jan 23, 2003
Messages
11
Location
Tromsø - Norway
Hi!
Have tried to find the answer to this question in the forum, but I have not found what I'm looking for, so I'm posting my problem hoping someone can help me.

I have this table in a MSSql database:
Code:
Category(catID, catName, catParentID)

The database can contain Categories(rootcategories), which can again contain an infinite number and levels of subcategories (althoug rearly more than five sublevels..) A rootcategory is indicated by a row in the Category table with catParentID=0, and a subcategory is indicated with a row where catParentID=catID from its parent category.

What I want to do is to reflect the content of this table in the database in a TreeView control in VB.NET.
I think it would be possible to do this with a recursive procedure, but when i try i get into trouble adding the subCategory nodes to the right place in the tree.

Does anyone have any suggestions how to do this an effective way?

--
Regards
Tor Inge
(Pardon my English, it's just my second language...)
 
The best way is probably to make your procedure accept a Nodes collection as one of the parameters. Then you create all the nodes at that level from the database, adding each to the nodes collection passed to the procedure then recursing, passing the Node.Nodes collection of that node.

A little wordy, but I think that's what you're trying to do.
 
Back
Top