Page 1
Page 2
Page 3
The leaf nodes were added as follows :
TreeView.Nodes.Add KeyStr, 4, strDisp, strDisp,
3
A leaf node has no children, so it is a good
idea to make a distinction between leaf nodes and their parent
nodes by giving the leaf nodes a distinguishing image. In our
example we use the bee bitmap.

Figure 4.
Each leaf node is added as a child of the
relevant Customer node, and to do this the customer key
string was used as indicated in the above line of code.
Each leaf node gets its own unique key
string in the variable "strDisp", which doubles (in
our example) as the text. The image parameter has a value of "3"
since we want each leaf node to have the bee image (this is the
third image in the Imagelist).
5) Now although we are discussing this last,
the following steps need to happen first, before we can display
information in our TreeView control. Firstly, an Imagelist control
needs to be placed on the form, so you will need to add the Imagelist
control to your toolbox if it isn't there already. Do this in
the same way that you added the TreeView control, only this time,
make sure that the 'Microsoft CE Imagelist control 3.0' checkbox
is checked.
We then need to add the necessary images to
the Imagelist control so that the TreeView control has images
to use when displaying its data. This is very easily done by using
the add method, as seen in the code below,
ImageList1.Add gImage1
ImageList1.Add gImage2
ImageList1.Add gImage3
where gImage1, gImage2, and gImage3 are defined
as follows :
Const gImage1 = "\My
Documents\icon_folder_closed.bmp"
Const gImage2 = "\My Documents\icon_folder_open.bmp"
Const gImage3 = "\My Documents\bee_icon_bmp.bmp"
The dimensions of the first image added to
the control, determine the dimensions of the rest of the images
that are added. The only constraint to the number of images that
can be added to the Imagelist, is the amount of available memory.
Please note that only images of type ".bmp", ".dib"
or ".2bp" can be added to the Imagelist control.
The TreeView control then needs to have a
way of referencing the Imagelist control and it does this by setting
its imagelist property to the Imagelist's hImagelist property
(handle to the Imagelist control).
TreeView.ImageList = ImageList1.hImageList
To run the code,
a) make sure that you copy the three images
across to your pocket pc.
b) Run the code and click "Create DB"
to create a database. Click "Create Tbl" to create a
table with 2 columns in it ("custid", and "customername").
The click "Insert Rows" to insert 5 rows into the table
to use with this example. Click "List Rows" to see the
list of the 5 rows. Then click "TreeView" to see the
information displayed in the TreeView control. By double-clicking
each node (except the root node), or by clicking on the plus or
minus sign, you will be able to expand and collapse the node.
Notice how the image changes as you do this.
There you have it, in the shell of a rather
small nut. I have just touched on the different components involved
in adding a node to a TreeView control using images in an Imagelist
control, but you now have a place to start. The accompanying code
should help to put what I have said into context.
Previous Page