Consulting

Results 1 to 9 of 9

Thread: Solved: ListView control with images

  1. #1
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    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:
    1. Add an imagelist control to the same form as the listview control
    2. 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.

  2. #2
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    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?

  3. #3
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    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.

  4. #4
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    demo

    Heres a demo file to help explain

    Not sure if the icons will be included or they have to be on your drive

  5. #5
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    Bump


    Anybody any experience of using trreview or listview with images?

  6. #6
    VBAX Master
    Joined
    Jul 2006
    Location
    Belgium
    Posts
    1,286
    Location
    Take a look at this file : http://puremis.net/excel/code/080.shtml

    Charlize

  7. #7
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location
    Thanks Charlize

    Looks like the answer should be in that lot somewhere!

  8. #8
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    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]
    Cheers
    Andy

  9. #9
    VBAX Tutor
    Joined
    Dec 2006
    Posts
    271
    Location

    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
  •