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
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