Visual Studio C# How can I Load a Gridview Thumbnail without locking the source file for delete

35 Views Asked by At

I am loading a Visual Studio Gridview cell with a thumbnail. I need to be able to delete or rename the source thumbnail file based on user input. When I try to rename or delete the code returns the error that the 'file is use' when I load the cell directly from the source file using:

fileGridView.Rows[dgIndex].Cells["thumbNail"].Value = Image.FromFile(tname);

I have tried to load the cell from cache with the following code, but get System.Format Exception. Cannot convert C:filename.jpg cannot be converted to type 'Image'.

        BitmapImage timage = new BitmapImage();
        timage.BeginInit();
        timage.CacheOption = BitmapCacheOption.OnLoad;
        timage.UriSource = new Uri(tname);
        timage.EndInit();
        fileGridView.Rows[dgIndex].Cells["thumbNail"].Value= timage;

What is the correct approach to loading the cell with the image without locking the source file (so I can rename or delete as required).

Gridview looks like: Gridview

Thank you in advance for your consideration of this issue!

0

There are 0 best solutions below