Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding images to listview subitems 1

Status
Not open for further replies.

memememememememe

Programmer
Jul 24, 2007
14
AU
I know this can be done I have seen it but am stumped and tired of searching for an answer.

I want to have more than one image in the listview control ie: add images to subitem(s), does anyone know?

Thankyou.
 
You've been fooled by the documentation ... which generally suggests using SubItems for additional info. However, you cannot add an image to a SubItem. What you need to look at are the closely related ListSubItems ...

This example needs a ListView, an ImageList with 3 images in it and a command button:
Code:
[blue]Option Explicit

Private Sub Command1_Click()
    Dim myItem As ListItem
    
    Set ListView1.SmallIcons = ImageList1
    ListView1.View = lvwReport
    
    ' make sure we've got at least three columns
    Do Until ListView1.ColumnHeaders.Count >= 3
        ListView1.ColumnHeaders.Add
    Loop
   
    ' Add item with a couple of subitems (hence our requirement for 3 display columns)
    Set myItem = ListView1.ListItems.Add(, , "Item", , 1)
    myItem.ListSubItems.Add , , "Subitem1", 2
    myItem.ListSubItems.Add , , "Subitem2", 3
End Sub[/blue]
 
I haven't had a chance to try it yet but I'm sure it will work coming from you strongm, I'll give you a vote once confirmed

Thanks! :)
 
Thanks very much works a treat.

The only problem I have now is sorting the list alphabetically, worked fine until I changed...

ListView1.View = lvwReport

any ideas?
 
I worked it out, I had to asign the 'SortKey' to one of the columns, thanks again for your help :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top