Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in treeview one specific node already added and now i have add child node for that specific Node.then how can i added child in existing nodes?

What I have tried:

string ItemName = "MTP/2 -3-PLY";
TreeNode node = new TreeNode(ItemName);
treeView1.Nodes.Add(node);
var opname = "op 1";
TreeNode childnode = treeView1.Nodes[ItemName]
childnode.Nodes.Add(opname);
Posted
Updated 23-Dec-19 21:16pm
v3
Comments
Richard MacCutchan 23-Dec-19 9:19am    
Do you have a question?
[no name] 23-Dec-19 10:08am    
The "node" you just added has it's own "Nodes" property. What do you think is the next logical step?

1 solution

If you would like to add a sub-node to the node, try this:
C#
string ItemName = "MTP/2 -3-PLY";
string subitemname = "op 1";

TreeNode node = new TreeNode(ItemName);
node.Nodes.Add(subitemname);
treeView1.Nodes.Add(node);


In case you want to add a childnode to the existing node, use this:
C#
var node = treeView1.Nodes[0]; //root node
node.Nodes.Add(subitemname);
 
Share this answer
 
v2

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