Vb. Implementation of hierarchical data binding TreeView in Net

Source: Internet
Author: User
Tags bind

Summary: In VB6, the TreeView is often used to represent hierarchical data, but the related code that interacts with the database requires a lot of manual coding; In vb.net, because of the enhancement of the data binding function and the enhancement of language features, it is easy to bind the TreeView to the hierarchical data, this article will first establish a dbtreeview that inherits from the TreeView and then use a unit (department) 's hierarchical data is bound to Dbtreeview and provides code to interact with the database.

1, from the level of data to express the way to start

In this example, the Department table (Department) has five fields, such as the following table:

Field name Field Type description
Id Automatic numbering Key
Code String Coding
Name String Name
Pid Int ID of parent Node
CPtr Boolean Do you have any child nodes?
  

2, inherit from the TreeNode Mytreenode

In Mytreenode, three new properties are added, such as the following table:

Property name Type Description
Value Object Key
Pid Object ID of parent Node
CPtr Boolean Do you have any child nodes?
  

In the Init event, set the three properties and the Text property, based on the four parameters passed in.

3, bind the Dbtreeview to the data source

Property name Type Description
Datasource DataView Dbtreeview data sources use DataView instead of object
Value Member String value member (column name of data source [DataView])
Display Member string display (in text) member
Pid Member String Parent ID Member
CPtr Member Whether string has child nodes
  

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.