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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding icons to listview from imagelist 1

Status
Not open for further replies.

MajP

Technical User
Aug 27, 2005
9,382
US
Sorry about the double post. I originally posted in the Access forums, but this is probably a better venue and different audience.

I am trying to simply add some icons to a listview using an imagelist.

Code:
Option Compare Database
Option Explicit

Public imgLstObj As MSComctlLib.ImageList

Private Sub Form_Load()
  Call loadImgLst
  Call loadIcon
End Sub

Public Sub loadImgLst()
  Set imgLstObj = Me.imgLstOne.Object
  imgLstObj.ListImages.Add , "Pic 1", LoadPicture("C:\TEMP\Pic1.JPg")
  imgLstObj.ListImages.Add , "Pic 2", LoadPicture("C:\TEMP\Pic2.JPg")
End Sub

Public Sub loadIcon()
  Dim lvObj As ListView
  Set lvObj = lstVwOne.Object
  Set lvObj.SmallIcons = imgLstObj
  lvObj.View = lvwSmallIcon
  MsgBox imgLstObj.ListImages(1).Key
  'error next line.
 lvObj.ListItems.Add 1, "A", "Test", "Pic 1"
 lvObj.ListItems.Add 2, "B", "Test2", "Pic 2"
End Sub

I get an error when I try to add the picture to the 1st item of the listview. The error is
"image list must be initialized before being used"

Prior to the error I put the Msgbox
MsgBox imgLstObj.ListImages(1).Key
and it returns the key of the first image so I do not understand the error message. Thanks for any help.
 
You try to use Icons list, whereas only SmallIcons list was intialised.
From object browser:
Function Add([Index], [Key], [Text], [Icon], [SmallIcon]) As ListItem
So you need:
Code:
lvObj.ListItems.Add 1, "A", "Test", [!],[/!] "Pic 1"
 lvObj.ListItems.Add 2, "B", "Test2", [!],[/!] "Pic 2"




combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top