Dong Lam Trien

Dong Lam Trien

  • 829
  • 986
  • 145.9k

why not remove the ghost image with this.listView1.Controls.Add(pictur

May 26 2023 4:21 AM

in c#, when i add item to listView1 there will be two images via command:

string imgName = ImageList1.Images.Keys[i].ToString();
item.ImageIndex = ImageList1.Images.IndexOfKey(imgName);
listView1.Items.Add(item);
listView1.Update();

PictureBox pic = new PictureBox();
...
listView1.Controls.Add(pic);

adding item to listView1 works fine but when removing item, the image is ok
added by listView1.Controls.Add statement is not deleted, I want to delete this image, how do you write the command? you see my delete code

PictureBox pic = (PictureBox)listView1.SelectedItems[0];
listView1.Controls.Remove(pic);
listView1.SelectedItems[0].Remove();

Answers (3)