Winform treeview: Add sub-nodes by node name, winformtreeview

Source: Internet
Author: User

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 "));

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.