Populating a TreeView from a relational database

T

tzvikaz

Let's say I have this db:

Table: Companies
-------
Ford
Toyota
BMW

Table: CarTypes
--------
Sedan
Van
Compact

Table: Colors
------
Red
Blue
Orange
Yellow
Green
Black

Table: Cars
----
ID Color Type Company
-- ----- ---- -------
1 Green Sedan Toyota
2 Red Sedan Toyota
3 Red Van Toyota
4 Blue Van Toyota
5 Blue Sedan Ford
6 Yellow Sedan Ford
7 Yellow Compact Ford
8 Orange Compact Ford
9 Black Sedan BMW

Color, Type and company are foreign keys

I want to represent that in a TreeView
Which will look like this:
Company
|
|-Toyota
| |-Sedan
| | |- Green
| | |- Red
| |-Van
| | |-Red
| | |-Blue
| |
|-Ford
| |-Sedan
| | |-Blue
| | |-Yellow
| |-Compact
| | |
| | |-Yellow
| | |-Orange
| |
|-BMW
| |-Sedan
| |-Black

Any ideas how to implement such thing?
Be as specific as you can

Thanks.
 
A

Alexander Shirshov

I can think of several ways, which one is the best depends on several
factors.

Are you using MSSQL 2000? You could query FOR XML and then work with DOM.

Do you know how to create and work with DataRelations in DataSets? You could
reproduce the hierarchy in a DataSet first and then it's quite easy to fill
the TreeView.

HTH,
Alexander
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top