views:

206

answers:

2

How can I replace an existing image on a winforms ImageList?

I tried this:

this.CoolPics.Images [ 2 ] = // new image
this.ListViewControl.SmallImageList = this.CoolPics;

However the new image is not rescaled the way the others are, when I used the this.CoolPics.Images.Add method.

What am I doing wrong?

A: 

after your code try

listView1.Refresh();
pho3nix
Thanks, will give it a try today.
Joan Venge
I just tried it but it didn't work. It changed the image but the image wasn't rescaled like when I first added the images.
Joan Venge
A: 

I have run into this before and if I remember right the assignment operator had this behavior but the Imagelist.Images.Add(myImage) did the right thing.

Try changing your code to do the .Add(myImage) and see if that doesn't look better.

Jeff Alexander
Thanks, the only problem with that would be that I would have to either remove the old one, which would change the other listview items (?) or the imagelist would grow with unused items.
Joan Venge
I don't know why the ImageList ImageCollection has a RemoveAt but not an Insert. Seems to be missing functionality. Total hack but you could Add it, save the returned index of the add, use the = to assign the index you want with the new index, then use RemoveAt to remove the added one with the saved index...
Jeff Alexander