Hello there,
How can i add a node in a certian place in a treeView control?

Thanks ahead

Recommended Answers

All 13 Replies

Does this answer your question?

first thanks,
but it dosent help me since i need to add a node i a certian place

but it dosent help me since i need to add a node i a certian place

Why doesn't it help? It shows you that you can add and remove from the collection. That means you can copy the collection to a list that you can edit using indexes, clear the collection, and then add the range of the edited list back to the empty collection.

Member Avatar for iamthwee

maybe he/she doesn't know how to find that certain place to begin, i.e they don't know how to traverse the tree (so-to-speak)?

I guess that I understand your question u can use the code
treeView1.Nodes.Insert(2, new TreeNode("Forth tree node"));

The insert method enable u add a node in a targeted place

if I needs to get the index of the last node in the tree, how can I do that.
In the Add() method, it normally add the new node to the end of the tree, so how the add method find the last position...?

TreeView treeView1 = new TreeView();
treeView1.Location = new System.Drawing.Point(1, 0);
treeView1.Name = "treeView1";
treeView1.Size = new System.Drawing.Size(153, 204);
this.Controls.Add(treeView1);
treeView1.Nodes.Add("Sample_Node");
treeView1.Nodes[0].Nodes.Add("sample1");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.