views:

37

answers:

1

This is probably a dumb question, but I've hit a wall with this one at this current time.

I have some data which is hierarchial in nature which is in an ADO.NEt dataset. The first field is the ID, the second is the Name, the third is the Parent ID.

ID NAME Parent ID
1 Air Handling NULL
2 Compressor 1
3 Motor 4
4 Compressor 1
5 Motor 2
6 Controller 4
7 Controller 2

So the tree would look like the following:

1- Air Handling
4- Compressor
6 - Controller
3 - Motor
2- Compressor
7- Controller
5 - Motor

What I'm trying to figure our is how to get the dataset in the same order that ths would be viewed in a treeview, which in this case is the levels at the appropriate levels for the nodes and then the children at the appropriate levels sorted by the name.

It would be like binding this to a treeview and then simply working your way down the nodes to get the right order.

Any links or direction would be greatly appreciated.

A: 

I would re-organize the data to be more normalized, however if you must work with what you have, do nested for statements (where the first one looks for the null in the parentID field. If you don't know how many layers deep the data goes, it will make your job more difficult, but it can be done.

DaMartyr