In my list, I show thumbnails of small images in a specific folder. I configure listview as follows:
var imageList = new ImageList(); foreach (var fileInfo in dir.GetFiles()) { try { var image = Image.FromFile(fileInfo.FullName); imageList.Images.Add(image); } catch { Console.WriteLine("error"); } } listView.View = View.LargeIcon; imageList.ImageSize = new Size(64, 64); listView.LargeImageList = imageList; for (int j = 0; j < imageList.Images.Count; j++) { var item = new ListViewItem {ImageIndex = j, Text = "blabla"}; listView.Items.Add(item); }
The user can right-click on the image in the list to delete it. I delete it from the list and then want to remove this image from the folder. Now I get an error that the file is being used. Of course, this is logical, since imagelist uses the file.
I tried to remove the image from imagelist first, but I continue to store the file.
Can someone tell me what I'm doing wrong?
Thanks!
source share