Imagelist and ListView...

I would like to show a list of items with images in a listview. And I have write code to add picture dynamically into an Imagelist and display the items with the images from the imagelist in a listview.
However, if I want to refresh the content, I can't clear the images in the imagelist as it was bound to the listview already. Is there is any method or other means so that I solve this problem?

Thx.

Samuel
LVL 1
LCPAsked:
Who is Participating?
 
caraf_gConnect With a Mentor Commented:
Set YourListView.ImageList = Nothing
'Clear your images and do what else you need to do
Set YourListView.ImageList = YourImageList
0
 
caraf_gCommented:
Sorry, in VB6 you don't have the .imagelist property, instead you can use the following 3 properties:

for example:
Set Me.ListView1.Icons = YourImageList
Set Me.ListView1.SmallIcons = YourImageList
Set Me.ListView1.ColumnHeaderIcons = YourImageList

Apart from using "Icons", "SmallIcons" or "ColumnHeaderIcons" instead of ImageList, the principle is the same.

Sorry for the misleading initial answer.
0
 
amebaCommented:
There are two ways:

    lvTabName.ListItems.Clear
    Set lvTabName.Icons = Nothing
    Set lvTabName.SmallIcons = Nothing
    ' Clear all Images, but first
    For i = il1.ListImages.Count To 2 Step -1
        il1.ListImages.Remove i
    Next
    For i = Il2.ListImages.Count To 2 Step -1
        Il2.ListImages.Remove i
    Next
    Set lvTabName.Icons = il1
    Set lvTabName.SmallIcons = Il2
    ' now you can add images to Imagelists il1 and il2, e.g.
    Dim imx As MSComctlLib.ListImage
    Set imx = il1.ListImages.Add(, "i" & varrkeys(2, i), picLvIcon.Image)
    Set imx = Il2.ListImages.Add(, "i" & i, picLvIcon.Image)

The other way is using ImageList_ReplaceIcon API, see:
http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=36
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LCPAuthor Commented:
Thx. Your ans is good.
What can I do if I want to change the image content at runtime?
For example, in a slow connection network, I want to show the item first before the image to be loaded from the other side of the network. Can I show the items content first with a default image from the imagelist and then update the images in the imagelist later even it was bounded to a listview already?
0
 
amebaCommented:
Hmm... I hope my additional info did not result in marking caraf_g's correct answer as B.
0
 
caraf_gCommented:
C'est la vie. :-(
0
 
LCPAuthor Commented:
caraf g's answer is already very good. I am just a little bit greedy. :P

I have try the ImageList_ReplaceIcon API,  it said "The file must have been saved using the SaveImageList control..", but I can't understand what it mean, how to save the images into a file for the API to be use? what format and how??

Thx anyway.

Samuel
0
 
caraf_gCommented:
You have to be careful. Next time you ask a question I might think "Hm... LCP gave me a B the last time. I better skip this one".

Aaah... You know I won't. But I could. You know. In theory, like. erm...
0
 
amebaCommented:
I mentioned ImageList_ReplaceIcon - the link shows its declarations and sample of using it.
If you are interested in the sample, it is used with the other sample, which is on the same site, Code bank section.
0
 
amebaCommented:
the other sample is:
SaveImageList - Save the images in an ImageList control
http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=35
0
 
LCPAuthor Commented:
I still can't use the code, I am using VB5. When the code come to "Dim pb as new propertyBag", it said invalid use of new keyword..
I am so frustrated.... :<

Samuel
0
 
amebaCommented:
No, you cannot use it in VB5.
0
 
LCPAuthor Commented:
Too bad.. thx anyway.

I have use another method to solve it. Since Imagelist do not allow remove of images,  I can still add image into it...
so I add image and change the item's icon and smallicon property to the new added image so that I can change the icon show.
it is a little bit waste of resources, but it work fine.
Thank so much.

Samuel
0
 
amebaCommented:
>I have use another method to solve it.
That's good (B) :)
0
 
MoondancerCommented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.

This is the Community Support link, if help is needed, along with the link to All Topics since many new ones were recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0
All Courses

From novice to tech pro — start learning today.