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

Populate listview icons with imagelist 1

Status
Not open for further replies.

MajP

Technical User
Aug 27, 2005
9,382
US
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.
 [b]lvObj.ListItems.Add 1, "A", "Test", "Pic 1"[/b]
 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.
 
Try this..

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 [COLOR=red]1[/color], "Pic 1", LoadPicture("C:\TEMP\Pic1.JPg")
  imgLstObj.ListImages.Add [COLOR=red]2[/color], "Pic 2", LoadPicture("C:\TEMP\Pic2.JPg")
End Sub

Public Sub loadIcon()
  Dim lvObj As ListView
  Set lvObj = lstVwOne.Object
  Set lvObj.SmallIcons = imgLstObj
  [COLOR=red]lvObj.Icons = imgLstObj[/color]
  lvObj.View = lvwSmallIcon
  MsgBox imgLstObj.ListImages(1).Key
  'error next line. [COLOR=red]
 lvObj.ListItems.Add 1, "Pic 1", "Test", [b]"Pic 1"[/b], "Pic 1"
 lvObj.ListItems.Add 2, "Pic 2", "Test2", [b]"Pic 2"[/b], "Pic 2"[/color]
End Sub


________________________________________________________
Zameer Abdulla
Help to find Missing people
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top