0
Reply

How to delete or Remove Item with image from ListView in C#?

sudhakargm

sudhakargm

Feb 14 2005 6:20 PM
4.7k
How to delete or Remove Item with image from ListView in C#? I am creating a ListView and setting a LargeImageItem. I am adding each item of string and index of the image. I also adding image to LargeImageList. Here is the code snippet in C#.NET ListView lstView = null; String fileName; int index = 0; private void addImage(filename, index){ lstView.Items.Add(fileName, index); lstView.LargeImageList.Images.Add(Image.FromFile(fileName)); ... } Now I want to remove item from the ListView. Here is sample code. private void removeImage(index){ lstView.LargeImageList.Images[index].Dispose(); -----line 1 lstView.LargeImageList.Images.RemoveAt(index); -----line 2 lstView.Items[index].Remove(); --line 3 //lstView.Items.RemoveAt(index); --line 4 lstView.Invalidate(); ... } If I use line 1,2,3 then if I try to delete 3rd image out of 5 image item in the list then it deletes 3rd image also deletes last image. If I use only line 3 or 4 then while deleting it works fine but if I add another image then it keeps the old image list pattern no matter which image I add. Does anyone come across this problem? If anyone knows better idea, How to delete ListView item with image associated? And also able to add item after wards. Hope it is interesting problem. Thanks in advance J - Sudhakar