I want to dynamically add some child nodes to a root node in my TreeView
. I have a string Array
of some names like {\"john\", \"sean\", \"edw
I think the problem is that you do not inform the mainNode that child is its children, something like: mainNode.Children.Add(child) (in the for block). You just create the child node, but you don't do anything with it for it to have any relation with the TreeView or with the mainNode.
You need to append the child node to the parent, here's an example:
TreeView myTreeView = new TreeView();
myTreeView.Nodes.Clear();
foreach (string parentText in xml.parent)
{
TreeNode parent = new TreeNode();
parent.Text = parentText;
myTreeView.Nodes.Add(treeNodeDivisions);
foreach (string childText in xml.child)
{
TreeNode child = new TreeNode();
child.Text = childText;
parent.Nodes.Add(child);
}
}