Add Node to TreeView Control: Quick Guide
To add nodes in a treeview control, you can utilize the Add method of the Nodes collection. Below is an example code:
// 创建一个根节点
TreeNode rootNode = new TreeNode("根节点");
// 添加子节点
TreeNode childNode1 = new TreeNode("子节点1");
TreeNode childNode2 = new TreeNode("子节点2");
rootNode.Nodes.Add(childNode1);
rootNode.Nodes.Add(childNode2);
// 将根节点添加到treeview控件中
treeView1.Nodes.Add(rootNode);
In the given example, start by creating a root node. Then use the Add method to add child nodes to the root node’s Nodes collection. Finally, use the Add method of the Nodes collection to add the root node to the treeview control’s Nodes collection.