C # TreeView Infinite Directory Tree Implementation method _c# Tutorial

Source: Internet
Author: User

The example in this article describes the implementation of the C # TreeView infinite directory tree. Share to everyone for your reference, specific as follows:

#region bind customer tree protected void Bindtreeview () {TreeView1.Nodes.Clear (); string userid = session["userid"].
  ToString (); String sqlwr = new Sy_adminuser ().
  Getuseridlistbyloginuser (userid, "CustomerService", false); DataTable dt = Maticsoft.DBUtility.DbHelperOra.Query ("Select Parentid,customerid,customershort,customerservice" from Cu_customer where isdelete= ' 0 ' "+ sqlwr +" ORDER by Customershort ").
  Tables[0];
  Defines the temporary tree node TreeNode TMPND; Special handling foreach (DataRow dr in Dt. Rows) {datarow[] drs = dt.
    Select ("customerid= '" + dr["ParentID"] + "" "); if (DRS).
    Length = = 0)//No superior node {dr["parentid"] = "0"; } dt.
  AcceptChanges (); An array of DataRow formed from all the parent nodes in the datatable datarow[] rows = dt.
  Select ("parentid= ' 0 '");
    Traverses the root node array foreach (DataRow row in rows) {TMPND = new TreeNode (); Assign a value to the root node Tmpnd.value = row["CUSTOMERID"].
    ToString (); Tmpnd.text = row["Customershort"].
    ToString ();
    Tmpnd.expanded = true; Add a node to the tree treeview1.nodes.ADD (TMPND); Addtree (DT, TreeView1, TMPND, row["CUSTOMERID").
  ToString ()); } public void Addtree (DataTable dt, TreeView TV, TreeNode Pnode, String CUSTOMERID) {datarow[] rows = dt.
  Select ("parentid= '" + CUSTOMERID + "");
  TreeNode TMPND;
    foreach (DataRow row in rows) {TMPND = new TreeNode (); Assign a value to the root node Tmpnd.value = row["CUSTOMERID"].
    ToString (); Tmpnd.text = row["Customershort"].
    ToString ();
    Tmpnd.expanded = true;
    PNODE.CHILDNODES.ADD (TMPND);
    Add a node to the tree//treeview1.nodes.add (Pnode); Addtree (DT, TreeView1, TMPND, row["CUSTOMERID").
  ToString ());

 }} #endregion

Read more about C # Interested readers can view the site topics: "C # Programming Thread Usage Tips summary", "C # Operation Excel Skills Summary", "C # XML file Operation Tips Summary", "C # Common control usage Tutorial", "WinForm Control Usage Summary", "C # tutorial on data structure and algorithms, summary of C # array manipulation techniques, and an introductory course on C # object-oriented programming

I hope this article will help you with C # programming.

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.