Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best Way to Add Hierarchical DataSet to TreeView

Status
Not open for further replies.

dougcoulter

Programmer
Mar 16, 2001
112
US
Hello all - I've got a problem I've been struggling with the last day or so. I have a DataSet composed of 5 tables, each related in a hierarchical fashion (i.e.: Table1 is the root, Table2 only has items that are related to Table1, Table3 only has items that are related to Table2, etc.)

I would like to display the rows of these tables hierarchically via the TreeView control and am wondering what would be the most efficient way. I am thinking something recursive in nature, but I've never been very good at thinking recursively. I currently have added the nodes for the top level from Table1 and am wondering if at the same time I should add the related child nodes for each using the GetChildRows method. If I do that, I am not sure where to go from there.

Can anyone straighten me out? I think I've been thinking about this too long and maybe not in the right way.
 
Have you looked at the DataGrid? It has what may (may not) be what you're looking for. With hierarchical data, it'll display the top node records with a plus expand down to child rows and so on.
 
Thanks - I have, I feel it's just not as intuitive for a novice user; whereas the tree view has become almost second nature to most Windows users.

I think the TreeView is a perfect fit for this type of data (even though it will more difficult to develop).

I am pretty certain I can solve the problem through some brute force methods - but I'd prefer something efficient if not elegant - especially if the DataSet becomes large in nature.
 
Okay - I think I have figured this out. For each row in the root table, I am calling an AddNode custom method, which adds the node in question first and then recursively calls itself for each of its child rows.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top