By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,563 Members | 1,768 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,563 IT Pros & Developers. It's quick & easy.

Populating a TreeView from a relational database

P: n/a
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.

Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
i had to do something similar before and used this reference.

http://weblogs.asp.net/rosherove/arc...6/16/8726.aspx

Nov 16 '05 #2

P: n/a
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
<tz*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.