Treeview - imagelist and right click

SunWuKung

Registered User.
Local time
Today, 16:53
Joined
Jun 21, 2001
Messages
172
Hi I started to work with a Treeview control.
I ran into two problems.

1. I couldn't find out how to add images to nodes - I see that i have to work with an imagelist, but I don't know how.

2. I would like to use context sensitive menus when I right click on a node. I can get a message box pop-up with the key of the node on a right click, but I don't know how to build a menu for the right-click.

Thanks for any help.
SWK
 
You select the image from the imagelist on the SET NODE:
Set nod = tv1Cntl.Nodes.Add(Key:=NKey, Text:=rs1![Description], Image:=I1)

In this example nod is my NODE object, NKey contains the NODE KEY, rs1![Description] contains the text to display on the NODE and I1 is the index of the image in the imagelist to use.

Don't know about the right menu click
 
Hi Fofa,
yes, but how do I add and initialize an imagelist and how do I add images to it in VBA?

Many thanks for the help.
SWK
 
I think I prepopulated mine with 3 different sets of images in the form designer, and I have a frame with check buttons so the users can select a set of images, or none to use. When I populate or refresh the node list, I check this frame and set the index variables (I1 and I2 because I use only 2 images) and use those references on the set nod. I have 6 images (3 sets) populated in the imagelist.
 
Ok, so I can create and add images to the imagelist through the GUI.
But how do I tell the Treeview to use the imagelist I have created?
 
See my first post.
If the user changes images, you have to repopulate the treelist control to set the new images to the best of my knowledge. I don't know if it is possible to traverse the tree and change the index reference, or if the actual image is part of the node. I just force a repopulation of the treelist control when they switch images.
 
I use this line of code - it looks similar to yours.
Set nodCurrent = objTree.Nodes.Add(, , strKey, strText, Image:=1)

But it gives an error message: Cant add child - Imagelist must be initialized before it could be used.
 
I've got it now:
Set objTree.ImageList = Me.ImgList.Object

Do you know how to change the picture on expand - not on select.
 
I thought working with a treelist was a little "quirky". I setup all my code in a module.
First I declare this: Public tv1Cntl As Object
Then I set that object to my forms treelist control as such
Set tv1Cntl = Forms![fEntity_Maint]![Entity_View]
Then I reference the defined object in all my code.

Also I had to define a node object like this: Public nod As Object
and you can see from my first post I use that when I create the nodes.
 

Users who are viewing this thread

Back
Top Bottom