Example of tree and Database Association operations in WinForm (C #)

Source: Internet
Author: User
Data | database WinForm tree and Database Association operations are common, and the following code is used in projects to generate trees from a table:

Dataview?dvtree;
???????? Private?void? Inittreebydataset (? Treenodecollection?nds,?string?parentid, huh? Dataset?ds?)
???????? {
???????????? Dvtree?=?new? DataView ();
????????????
???????????? Treenode?tempnode;
????????????
???????????? Dvtree.table?=?ds. Tables[0];

???????????? Determine if the Parentservicetypeid is null and generate different filter conditions
???????????? If? (? parentid?==?) Isnull (Parentservicetypeid, ' Null? Column ')? =? ' Null? Column ' "?)
???????????? {
???????????????? Dvtree.rowfilter?=?parentid?;
????????????}
???????????? Else
???????????? {
???????????????? Dvtree.rowfilter?=? " Parentservicetypeid?= ' "? +?parentid?+" ";
????????????}
????????????
???????????? Foreach? (? Datarowview?drvtree?in?dvtree?)
???????????? {
???????????????? Tempnode?????? =?new? TreeNode ();
???????????????? tempnode.text?=?drvtree["Name"]. ToString ();
???????????????? Tempnode.tag?? =?drvtree["Pkfieldvalue"]. ToString ();
????????????
???????????????? Nds. ADD (Tempnode?);

???????????????? Recursive call
???????????????? Inittreebydataset (Tempnode.nodes,?tempnode.tag.tostring (), DS?);
????????????}
????????
????????}

Two RELATED links: The application of tree-shaped structure in development,
Select the tree node to display its detailed information



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.