Treeview Control Images Problem

D

David M C

I've looked at the various treeview examples (Alex Dybenko's etc) and
modified them to suit my needs. Everything works as expected until I try to
add images to the tree.

As far as I'm aware, you create an imagelist control, insert the images and
give them a key. You bind the imagelist to the treeview and as you add nodes,
you use the 5th argument to pass the key to the image you wish to display.

I store the key for each node in a table (along with information about the
nodes themselves (based on the treeview switchboard sample from Intuidev).
The code loads a recordset (the table containing the node information) and
builds the treeview. If I remove the 5th argument when adding nodes
everything works, adding the 5th argument gives me a runtime error "35603
Invalid Key". When I go to the debug window, each variable used to create the
node contains the expected information.

Here's the code:

'Everything before this point creates the recordset etc

tvSB.nodes.Clear
Set tvSB.ImageList = Me!tvImages.Object

With rs
'Loop through all switchboard-items, adding them to the treeview
While Not .EOF
'Assemble a key for this node, consisting of three arguments:
'
' 1. The ID - required to find a child-node's parent
' 2. The "Object-type" - form, report, etc.
' 3. The "Object-Name" - the name of the form, report, etc.
' 4. Additional stuff (i.e. OpenArgs being passed to a form)
strKey = !SB_ID & ";" & Nz(!SB_ObjectType) & ";" &
Nz(!SB_ObjectName) & ";" & Nz(!SB_Additional)

If !SB_Parent > 0 Then
'This node is a child-node of some other node;
'Find the parent node and add it below that node's last child
tvSB.nodes.Add getNodeIndex(!SB_Parent), tvwChild, strKey,
!SB_NodeTitle, !SB_ImageKey
Else
'There is no parent - add this node to the treeview's root
tvSB.nodes.Add , tvwLast, strKey, !SB_NodeTitle, !SB_ImageKey
'Error
End If

.MoveNext
Wend
End With

'Cleanup code

There may be some line feeds in the posting that aren't in the actual code.
If I omit !SB_ImageKey from the code everything works.

Dave
 
D

David M C

I added them through the ImageList controls property dialog.

I have heard of numeric keys causing problems when adding nodes, but this
was related to the key for the node itself. Just to be safe, I made sure all
the images had a text only key.
 
D

David M C

If I change the line:

tvSB.nodes.Add , tvwLast, strKey, !SB_NodeTitle, !SB_ImageKey

to:

tvSB.nodes.Add , tvwLast, strKey, !SB_NodeTitle, Val(!SB_ImageKey)

and store the index of the image in the table instead, then it works. I'd
still like to know why I couldn't use the text key instead, as everyone else
seems to.

Dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top