So I have encountered a probleem while trying to populate a TreeView control with nodes. I hope that there are a some kind people who täke the time and help me figuure out a correct solution.

So lets say I have 3 arrays:

["Example", "2", "1"]

{"Example", "2", "2"]

["Example", "3", "0"]

I know that my arrays have always exactly 3 elements in them, so the treeview will never have more than 3 childnodes

But all I am able to get is

Example

2

1

Example

2

2

Example

3

0

But the goal would be:

Example

2

1

2

3

0

So where would I start chasing down the answer to my probleem?

Big thanks in advance

Best Answer
**Andre S.**
,
27 December 2013 - 22:42

void InitTreeView(List<string[]> arrays) { foreach (var array in arrays) { AddArray(array, 0, m_treeView.Nodes); } } /// <summary> /// Recursively adds each element of the array to the tree /// </summary> void AddArray(string[] array, int index, TreeNodeCollection nodes) { // Termination condition: we've past the bounds of the array if (index < array.Length) { var nextNode = AddValue(array[index], nodes); AddArray(array, index + 1, nextNode.Nodes); } } /// <summary> /// If the value exists, returns it, otherwise creates a new value /// </summary> TreeNode AddValue(string value, TreeNodeCollection nodes) { var index = nodes.IndexOfKey(value); if (index == -1) { var newNode = new TreeNode(value) { Name = value }; nodes.Add(newNode); return newNode; } return nodes[index]; }Go to the full post