Skip to main content

Past Blast

Featured Products

Stay in touch using the DEVBUSS RSS feeds.
 

News

eVB Treeview control and ImageList control.

Written by Carole Mitchell  [author's bio]  [read 67747 times]
Edited by Derek

Page 1  Page 2  Page 3 

4) The GetInfoFillTree subroutine is where the information is read from the database and displayed in the TreeView control. The code for adding a node to a tree is the following :

TreeView.Nodes.Add , , "Root", "Customer Information"
and
TreeView.Nodes.Add "Root", 1, KeyStr, "Customer " & CStr(rs.Fields(0).Value), 1
and
TreeView.Nodes.Add KeyStr, 4, strDisp, strDisp, 3

The above follows the syntax for adding a node (obtained from the eVB Help File) which is as follows :

nodes.Add([relative], [relationship], [key], text, [image], [selectedimage])

As you can see the only essential part of adding a node to a tree is the text. The rest simply determines where the text will be placed in the tree in terms of the hierarchy or what the image and selected image will be. In our example, our TreeView control has a style of 7. This means we are using treelines,the plus and minus signs, and a picture (image) for each node. We are not going to be setting an image for the root node since this is just a description node (in our example), but we will be using an image for the other nodes. To do this we will be setting the value of the image parameter when we add a node to our TreeView control, but first take a look at what the parameters are for the add method and then we will discuss our example...

The following was taken directly out of the Microsoft help file found in eMbedded Visual Basic 3.0 for Windows CE development.

Parameters
nodes
Required. The name of a Nodes collection.

relative
Optional. The key of a pre-existing Node object or a Node object. The relationship between the new node and this pre-existing node is found in the relationship parameter.

relationship
Optional. Specifies the placement of the Node object in relation to relative.

key
Optional. Unique string expression that can be used to access a member of the Nodes collection.

text
String associated with the TreeView control.

image
Optional. Integer that sets the icon to be displayed from the ImageList control associated with the TreeView control.

selectedimage
Optional. Integer that sets the icon to be displayed from an ImageList control when the Node is selected

To display a heading "Customer Information" as the root node's text we use the following line of code :

TreeView.Nodes.Add , , "Root", "Customer Information"

Since this is the first node in the tree, it is not related to anything else and so I gave it a key string of "Root" so that it would be easy to link other nodes to it. The key string parameter is used to identify the node uniquely and it enables you to link other nodes to it hierarchically as you choose.

Next we want to list all our customers under this heading, and allow the user to expand each customer id to get more customer details, should he or she wish to. Each of the customer ids (you would obviously use more meaningful data in a real example) is displayed as a node under the root node, and these are each added as follows :

TreeView.Nodes.Add "Root", 1, KeyStr, "Customer " & CStr(rs.Fields(0).Value), 1

where "Root" is the key of the node it is being linked to. The next parameter ,"1", makes the node appear at the end of the list of nodes (as more nodes are added and the tree grows, I wanted the next node that is added, to appear as the last node in the list, instead of appearing second in the list, right after the root node, which using the default value of "2" would do). The key string is the next parameter - the variable "keyStr", and this variable contains a value that uniquely identifies this node. A constant "cust" and the customer id is used to make this string unique.

The next parameter is the text, and again I used a constant string - "Customer", and again I got it to uniquely identify each customer using the customer number (id).

The next and last parameter I used was the image parameter. This value I made "1" to get the first image in the Imagelist control, which is the closed-folder image. The index for the first object in a collection is always 1. Thus the TreeView control will be loaded with all the customer ids listed under the heading "Customer Information" and each customer id node will have a closed-folder image, indicating that there is more information to be obtained by expanding the node.

Figure 3.

Previous Page  Next Page