recursion - C# Create TreeView recursively from list -


I currently have a list of programs already in programmatic form (Tupal), that I now have a treeview again , But it is struggling slightly with working right.

List example: Name | Level

  fruit | 0 apples | 1 green sepals. 2 golden tasty | 3 grandmother smith | 3 cox orange paper | 2 red apple 2 Pink Lady. 3 red tasty | 3 oranges | 1 Blood | 2 Mandarin 2 vegetables 0 Lettuce | 1 iceberg Romain 2 2  

then wants to be mine:

  fruit (0) - apple (1) - green apples (2) --- granny smith ( 3) - golden tasty (3) - cox orange paper (2) - red apple (2) --- pink lady (3) --- red tasty (3) - orange (1) - blood (2) - mandarin 2) Vegetables (0) - lettuce (1) - iceberg (2) - roman (2)  

Note: Completely working solution See the response from LarsTEC below for thanks!

I have taken away the wrong code / efforts and I will leave it for all those who have the same problem.

The "level" value of each node is the only reference for your parents, To reference the last node used, you can only have one level of dictionary:

  dictionary & lt; Int, treeNode & gt; Last Original = New Dictionary & lt; Int, triode & gt; (); Forchha (Tupal & LT; String, Int.; Foods in Foods) {tree node collection item; If (food.Item2 == 0) {items = treeView1.Nodes; } And {item = last painter [food. Item2 - 1] .Nodes; } TreeNode treeNode = item Add (food.Item1); If (last father's meal (meal ITM2)) {last painter [food. ITM2] = triode; } Else {lastParent.Add (food.Item2, treeNode); }} TreeView1.ExpandAll ();  

Comments