C #. Net Treeview. CS

Source: Internet
Author: User

 

Public void bindtreeview (datatable DT, ref Treeview tvname)
{
// Datatable. defaultview. Sort ("nodeseq, parentnode ");
Tvname. nodes. Clear ();
// Create the root node
Datarow [] parentrow = DT. Select ("parentnode = '0'", "nodeseq ");
Treenode rootnode = new treenode ();
Rootnode. Text = parentrow [0] [3]. tostring ();
Rootnode. Name = parentrow [0] [4]. tostring (); // The value of the primary key
Rootnode. Expand ();
// Rootnode. Selected = true;
Tvname. nodes. Add (rootnode );
Createchildnode (rootnode, DT );
}

Public void createchildnode (treenode parentnode, datatable)
{

Datarow [] rowlist = able. Select ("parentnode = '" + parentnode. Name. tostring () + "'", "nodeseq, parentnode ");
Foreach (datarow row in rowlist)
{
// Create a node
Treenode node = new treenode ();
Node. Name = row ["nodename"]. tostring ();
Node. Text = row ["treenode"]. tostring ();
Node. Expand ();
// Parentnode. childnodes. Add (node );
Parentnode. nodes. Add (node );
Createchildnode (node, datatable); // recursive call to find its own subnode
}
}

 

Client code:

Strsql = "select * From pal_mes_treenode where appname = 'pal _ mes 'and formname = 'frmstreadymaterial' and treename = 'tvline '";
Datatable = cesql. getdatatable (strsql );
Ccmrule. bindtreeview (datatable, ref tvline );
Tvline. expandall ();
Tvline. selectednode = tvline. nodes [0]. nodes [0];
Tvline. Focus ();

 

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.