WinForm TreeView adding child nodes by node name

Source: Internet
Author: User

/// <summary>        ///Add a People node (with TreeNodeCollection)/// </summary>        /// <param name= "TNC" >treenodecollection (node collection for TreeView)</param>        /// <param name= "Pid_val" >the 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 voidBind_leaves (DataTable DT, TreeView TNC,stringIdstringPidstringText,contextmenustrip contextMenuStrip1, ImageList imageList1) {DataView DV=NewDataView (DT);//Save a DataTable to DataView for easy filtering of dataTreeNode TN;//Create a node for the TreeView (TreeNode) to add the extracted data to the node            foreach(DataRowView DRVinchdv) {tn=NewTreeNode ();//Create a new node (learning name: an instance)Tn. Name = Drv[id]. ToString ();//Value of the node, typically the ID value of the databaseTn. Text = Drv[text]. ToString ();//The text of the node, the textual display of the node                foreach(TreeNode nodeinchTNC. 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 collection)//bind_leaves (DT, TN. Nodes, TN. Name, ID, PID, text);//Recursive (call this method again and again until the data is taken out)            }        }

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.