Click here to Skip to main content
15,887,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I'm using a TreeView in my C# program; all is ok for inserting nodes and Child nodes.
example:

C#
Node1  ____ Node11
      |____ Node12 _____ Node121
                   |____ Node122  

And would like to insert one node (X) before Node12 for example:

C#
Node1  ____ Node11
      |____ X _____ Node12_____ Node121
                         |_____ Node122

How to do this please?
Best regards.
Posted
Updated 25-Sep-13 10:10am
v2

It would be something like that:
C#
TreeNode tn = treeView1.Nodes.["Node12"];
treeView1.Nodes.Remove(tn);
treeView1.Nodes["root"].Nodes.Add(new TreeNode("X"));
treeView1.Nodes["X"].Nodes.Add(tb);

Note: Not tested (on animals ;) )!

Another way is to use TreeNodeCollection.Insert Method (Int32, TreeNode)[^] method.
 
Share this answer
 
Comments
ridoy 25-Sep-13 16:55pm    
nice,5ed!
Maciej Los 25-Sep-13 17:42pm    
Thank you, Shuvro ;)
 
Share this answer
 
Comments
Maciej Los 25-Sep-13 16:31pm    
Interesting link!
5ed!
ridoy 25-Sep-13 16:54pm    
Thank you,:)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900