Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My datatable looks like following:

parent_category_code category_code category_desc
ROOT CL Cardiology
CL CV Cardiovascular
CV IM Internal Medicine
ML MA Molecular Activity
ROOT ML Microbiology
ROOT ROOT GRMIpedia
Posted
Comments
BillWoodruff 25-Feb-12 5:33am    
Hi, Please tag your question to indicate whether this is WinForms or WPF or ?

Most important question: when you use the word "ROOT" are you talking about a TreeView with one Root Node which has, as its child Nodes, all other Nodes whose parent_category_code is "ROOT:" or: are you talking about a TreeView with multiple root Nodes ?

And, please clarify why the last entry shown has "ROOT" both as parent_category_code and category_code: what does that mean in terms of what you want displayed in the TreeView ?

What does it mean that "ML" appears both to be a root Node, and a child of a (or the only) Root Node ?

Another question: wouldn't it be easy to sort the DataTable so all the Root nodes appeared first ?

The best way you could improve this question is to show us, visually, the result you want to see by simulating a view of the resulting TreeView: you can do this inside your original question by using pre-tags where you can use indent.

I believe a non-recursive solution is possible here, but until you've clarified the question, I am not going to try to come up with some code.

Any answer I would give here would assume you had done the work to get your DataTable into an IEnumerable Form where you could traverse it with for, or foreach, and would assume that for each item in this IEnumerable, the three fields would be strings.

thanks, Bill

1 solution

Do you have any idea about Linq?
I have a code module based on Linq.Let me know if you are interested.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900