-
Solved: ListView control with images
Hi folks
Had a good search on here to find any examples of how to add images to a treeview (or listview) control but to no avail.
I understand the best way is to:
- Add an imagelist control to the same form as the listview control
- Set the properties of the treeview to use the imagelist
But I cant get the properties of the listview to recognise the imagelist
Obviously something basic I am missing.
How do I join the two together?
Last edited by lifeson; 06-11-2008 at 12:10 AM.
-
AFter a search on t'internet
found this quote
Re: TreeView + ImageList in VBA???
I can't find the original reference to it, but I do remember from *somewhere* that the TreeView had been deliberately crippled for VBA useage.
Is this true?
-
getting closer
I think I am getting closer
I have:
added a imagelist called icons
added an image to the imagelist with the key "Level1"
[VBA]Private Sub BuildTree()
Dim i As Long
Dim j As Long
Dim k As Long
Dim Title As String
Dim xNode As Node
Dim NodeKey As String
Dim NodeKey2 As String
j = wsTree.Range("A65536").End(xlUp).Row
With frmQuoteBuilder.TreeView1
.Nodes.Clear
.Nodes.ImageList = icons
.Nodes.Add , , "level1"
For i = 2 To j
Set xNode = .Nodes.Add
NodeKey = wsTree.Range("A" & i).Text
With xNode
.Key = NodeKey
.Text = NodeKey
.Expanded = True
.Bold = True
End With
Next i
j = wsTree.Range("C65536").End(xlUp).Row
For i = 2 To j
Set xNode = .Nodes.Add(wsTree.Range("B" & i).Text, tvwChild)
NodeKey = wsTree.Range("C" & i).Text
With xNode
.Key = NodeKey
.Text = NodeKey
End With
Next i
End With
Set xNode = Nothing
End Sub
[/VBA]
It burns and crashes but I think I am getting closer as the treeview now has a gap where the icon should be.
-
demo
Heres a demo file to help explain
Not sure if the icons will be included or they have to be on your drive
-
Bump
Anybody any experience of using trreview or listview with images?
-
-
Thanks Charlize
Looks like the answer should be in that lot somewhere!
-
The imagelist is being used but you have not told the nodes which image to use.
[vba]
With xNode
.Key = NodeKey
.Text = NodeKey
.Expanded = True
.Bold = True
.Image = 1 ' < use image 1 from imagelist
End With
[/vba]
-
Thanks
I love this forum
Thanks Andy for the fix
Thanks Charlize for the link to another great resource site
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules