Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...