Hello there,
How can i add a node in a certian place in a treeView control?
Thanks ahead
Hello there,
How can i add a node in a certian place in a treeView control?
Thanks ahead
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mike GoldPosted Aug 20, 2007, 12:57 PM
foundNode.ChildNodes.Add
or
foundNode.ChildNodes.Insert
depending on where you want to put the child node
kobi shaalPosted Aug 19, 2007, 1:55 PM
i did something like you said :
until now im using a recursive function which travel over my tree and when the function found the needed function it reutun the founded node.
now to this node i need to add a node so it will like a child to the founed node
how can i do it?
Thanks again
Mike GoldPosted Aug 19, 2007, 1:21 PM
I don't really understand the question.
you could loop through the nodes under the parent and when you find the node you need to insert after or before, use the Insert
for (int i = 0; i < myTreeView.Nodes.Count; i++)
{
if (myTreeView.Nodes[i] ==
{
myTreeView.Nodes.Insert(i, myNewNode);
}
if you need to search a lower level, use the ChildNodes of a TreeNode the same way.
}
kobi shaalPosted Aug 19, 2007, 3:31 AM
how can i found the index which represnt my needed node?
Thanks
Mike GoldPosted Aug 19, 2007, 12:22 AM
Add will add at the end of the Nodes collection,
The Insert method will add at a particular index in the Nodes collection
e.g.
myTreeView.Nodes.Insert(3, myTreeNode);