I am trying to simply add some icons to a listview using an imagelist.
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.
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.