View Full Version : Solved: ListView control with images
lifeson
06-10-2008, 12:30 AM
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 imagelistBut 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?
lifeson
06-10-2008, 07:00 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?
lifeson
06-10-2008, 07:10 AM
I think I am getting closer
I have:
added a imagelist called icons
added an image to the imagelist with the key "Level1"
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
It burns and crashes but I think I am getting closer as the treeview now has a gap where the icon should be.
lifeson
06-10-2008, 07:42 AM
Heres a demo file to help explain
Not sure if the icons will be included or they have to be on your drive
lifeson
06-11-2008, 12:30 AM
:hi:
Anybody any experience of using trreview or listview with images?
Charlize
06-11-2008, 02:36 AM
Take a look at this file : http://puremis.net/excel/code/080.shtml
Charlize
lifeson
06-11-2008, 02:50 AM
Thanks Charlize
Looks like the answer should be in that lot somewhere!
Andy Pope
06-11-2008, 04:51 AM
The imagelist is being used but you have not told the nodes which image to use.
With xNode
.Key = NodeKey
.Text = NodeKey
.Expanded = True
.Bold = True
.Image = 1 ' < use image 1 from imagelist
End With
lifeson
06-11-2008, 05:18 AM
I love this forum :thumb
Thanks Andy for the fix
Thanks Charlize for the link to another great resource site
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.