I’m working on a vb.net project and have a slight problem. I have a datagrid with a directory listing of bitmap files. When a row is selected, the file is shown in a picture box as a preview.
This works great. I want to be able to delete the bitmap file selected in the datagrid. I get a file in use error. I figured that this was because the picturebox was using the file, so I tried changing the picturebox image before the delete but this didn’t fix the problem. Through troubleshooting I found that any picture that was previewed at any time while the program is running is locked and can’t be deleted until I exit the program, whether I try to delete by hand from a command prompt or through Explorer.
Tried and failed. That’s what’s so frustrating. I am convinced that it’s the preview since I also have text files in the directory without preview and they delete without problem.
Here’s what I do before trying the delete command. This is basically the culmination of all of the things I tried to free up that file, none of which worked. I even put the sleeps in to give the OS time to do its business.
Hmm, that is pretty bizarre. :dubious: I can see why this is so frustrating.
Are you using .Net 2.0? If so, then try the following approach:
Me.picThumb.Load(filePath)
As a side question: is it possible that you have any other controls accessing that same image, during the preview? Or is the picture box the only object referencing it?
LilShieste
No, only the picture box. The only other reference to the bmp files is the datagrid which is filled with just a directory listing. I’m going to try it on a machine with a newer version of the framework if I can find such a machine. If it still doesn’t work, I’m abandoning that function and moving on with my life.