VB.net the TreeView control

Source: Internet
Author: User

A TreeView (Tree-structured) control is a hierarchical architecture that displays node objects, with each Node object containing a label and an optional point bitmap. The TreeView control is typically used to display the document headers, entries in the index, files and directories on the disk, or various other information that can be displayed as a hierarchy. The left part of Windows Explorer is a typical tree structure. The icon for the TreeView control in the Toolbox is as shown in the figure:

1.TreeView design of a good structure of the node
To create a tree structure as shown in the following illustration, follow these steps:

(1) Add a TreeView control to the form named TreeView1 and a ImageList control, named ImageList1;
(2) Add a bitmap file to the ImageList control, as shown in the following section of the ImageList control.
(3) Set the "ImageList" option in the TreeView property page to "ImageList1";
(4) Click on the "Nodes" option in the TreeView property page, the Tree Node Edit dialog box will pop up.
(5) Edit the hierarchical relationship of nodes in the tree node edit box
2. Edit nodes in the tree node editor
(1) Click the "Add root (Add root)" button, then in the node edit box appears a node (the default name is Noden), according to the needs of the tree, the other nodes added to the tree.
(2) Select the node you want to add a child node to, and click the Add Child node button to add a child node to the node in the currently selected node.
(3) Select the node you want to add the bitmap to, and then in the image (icon), Selected image (select icon), select the bitmap you want in the ImageList1.
(4) Click on "OK" button, in the TreeView1 will display the edited tree.
3. Add nodes to the tree at run time
The "Nodes.Add" method is used to add nodes to the TreeView. First select the node to add the nodes to apply this method, the node in the TreeView is the relationship between the parent node management node, that is, the set of child nodes is the parent node "Nodes" property, the "Index" property of a child node, depends on its position in the collection of child nodes, not the location of the node in the entire tree. According to this feature, if you want to find the specified node, you must follow the following syntax:
TreeViewName.Nodes.Item (INDEX1). Nodes.item (INDEX2) ...
The method for adding nodes is:
TreeViewName.Nodes.Item (INDEX1). Nodes.item (INDEX2) ... Add ("Nodetext")
Or
TreeViewName.Nodes.Item (INDEX1). Nodes.item (INDEX2) ... Add ("Objnode")
For example, in the above TreeView1 node2 node to add a child node "Node2child1", and then to the node Node2child1 add child node "Node2child1child1" can be written as follows code:

Protected Sub button1_click (Byval sender as Object,byval e as System. Eventargs)
     Dim Nodx as New TreeNode ()
     Nodx. text= "Node2child1"
     nodx. imageindex=2
     TreeView1.Nodes.Item (2). Nodes.Add (NODX)
     TreeView1.Nodes.Item (2). Nodes.item (0). Nodes.Add ("Node2child1child1") End
Sub

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.