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.