Winform treeview: Add sub-nodes by node name, winformtreeview
/// <Summary> /// Add a worker node (using TreeNodeCollection) /// </summary> /// <param name = "tnc"> TreeNodeCollection (node set of TreeView) </param> /// <param name = "pid_val"> value of the parent id </param> /// <param name = "id"> Database id field name </param> /// <param name = "pid"> database parent id field name </param> /// <param name = "text"> Database text field value </param> public static void Bind_Leaves (DataTable dt, treeView tnc, string id, string pid, string text, ContextMenuStrip contextMenuStrip1, ImageList imageList1) {DataView dv = new DataView (dt); // Save the able to DataView, to facilitate data filtering TreeNode tn; // create a TreeView node (TreeNode) to add the retrieved data to the node foreach (DataRowView drv in dv) {tn = new TreeNode (); // create a new node (named as an instance) tn. name = drv [id]. toString (); // Value of the node, which is generally the id Value of the database tn. text = drv [text]. toString (); // The node Text. The node Text displays foreach (TreeNode node in tnc. nodes) {if (node. name = drv [pid]. toString () {node. nodes. add (tn); tn. contextMenuStrip = contextMenuStrip1; tn. imageIndex = tn. selectedImageIndex = 1; break;} // tnc. nodes [drv [pid]. nodes. add (tn); // Add the node to the TreeNodeCollection (node set) // Bind_Leaves (dt, tn. nodes, tn. name, id, pid, text); // recursion (this method is called repeatedly until the data is obtained )}}
Add a parent node to a specific root node in winform treeview
The ShowCheckBoxes attribute of the treeview. You can add the checkbox attribute.
Add nodes as follows:
TreeNode tn = new TreeNode (); // create a new node
Tn. SelectAction = TreeNodeSelectAction. None;
Tn. Value = "Value"; // The Value of the node, which is generally the id Value of the database.
Tn. Text = "Text display"; // The Text of the node. The Text of the node is displayed.
This. TreeView1.Nodes. Add (tn); // Add the node to the TreeNodeCollection (node set ).
How does treeview in C # Add a subnode to a specified NAME node?
TreeNode node = treeView1.SelectedNode; // or another node
Node. Nodes. Add (new TreeNode ("new node "));