How to Create a Treeview based on the database

Source: Internet
Author: User
Database Structure ID int (4) primary key parentid int (4) Context nvchar (50) No null
**************************************** *******************************
Function Description
Public void addtree (INT parentid, treenode pnode, Treeview, datatable DT)
The Treeview is the Treeview control and the DT is the table in the dataset.

Call example:

Dt = (datatable) TD. retieretree ();
Addtree (0, (treenode) null, treeview1, DT );

Vs2005 C # Windows XP passed the test.
**************************************** ******************************* Public Void Addtree ( Int Parentid, treenode pnode, Treeview, datatable DT)
{

Dataview dvtree = New Dataview (DT );
// Filter the parentid to obtain all the current child nodes.
// Dvtree. rowfilter = "[parentid] =" + parentid;
Dvtree. rowfilter = " [Parentid] = " + Parentid;


Foreach (Datarowview row In Dvtree)
{

Treenode Node = New Treenode ();
If (Pnode = Null )
{ // Add Root Node
Node. Text = Row [ " Context " ]. Tostring ();
Treeview. nodes. Add (node );
// Node. Expanded = true;
Addtree (int32.parse (row [ " ID " ]. Tostring (), node, Treeview, DT ); // Recurrence
}
Else
{ // Worker Add the subnode of the current node
Node. Text = Row [ " Context " ]. Tostring ();
Pnode. nodes. Add (node );
// Node. Expanded = true;
Addtree (int32.parse (row [ " ID " ]. Tostring (), node, Treeview, DT ); // Recurrence
}
}
}

 

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.