Reputation: 1264
I'm working on a little program, which grabs some data and should display them on a Treeview or DotnetBars advTree control.
On a button click event there will be collected some data and the (string)output looks like this. (structure of treeviews)
myTree.add(1,-1,'','');
myTree.add(260, 1, 'All Releases', '');
myTree.add(6,260, 'Cat1', ''
myTree.add(7,6, '20.0.2'', ''
myTree.add(8,7, '20.0.21', '&some stuff'
myTree.add(9,7, '20.0.20a', '&some stuff'
myTree.add(10,7, '20.0.5', '&some stuff'
myTree.add(11,260, 'Cat2', ''
myTree.add(12,11, '12.2', ''
myTree.add(13,12, '12.2.77', '&some stuff'
myTree.add(14,12, '12.2.26', '&some stuff'
First Column contains the Node-ID and the second column contains the ID, which it is a child-node from. The third contains the Node Text, which should be shown in the treeview, the last is for later purpose (value output).
Result: (Treeview example)
How can I get the Treeview items added programmatically with all its child-items?
Upvotes: 0
Views: 1988
Reputation: 3101
class MyTreeNode
{
public String NodeTitle;
public List<MyTreeNode> children;
}
I would build my desired structure into an object then recursively search through the children property to see if I needed to add more branches.
public AddBranch(MyTreeNode parentNode)
{
MyTree.Add(parentNode.NodeTitle);
foreach (var node in parentNode.children)
{
AddBranch(node);
}
}
// Note this is a rough mock code just to give you an idea of what recursion is.
Upvotes: 1