Link to home
Start Free TrialLog in
Avatar of LCP
LCP

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of caraf_g
caraf_g

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of caraf_g
caraf_g

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.
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
Avatar of LCP

ASKER

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?
Hmm... I hope my additional info did not result in marking caraf_g's correct answer as B.
C'est la vie. :-(
Avatar of LCP

ASKER

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
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...
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.
the other sample is:
SaveImageList - Save the images in an ImageList control
http://www.vb2themax.com/Item.asp?PageID=CodeBank&ID=35
Avatar of LCP

ASKER

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
No, you cannot use it in VB5.
Avatar of LCP

ASKER

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
>I have use another method to solve it.
That's good (B) :)
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.

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