When an image is selected, it is copied to a local folder. When an image is removed, the following code is executed:
private void btnRemoveImage_Click(object sender, EventArgs e) { //dispose image object ((Image)_currentCell.Value).Dispose(); _currentCell.Value = null; //get filename string fileToDelete = dgSponsors.Rows[_currentCell.RowIndex].Cells["colImageFilename"].Value.ToString(); //delete the file if(File.Exists(fileToDelete)) //the file DOES exist File.Delete(fileToDelete); //this does NOT throw an exception //at this point the file is still visible in the directory and I can delete it without problems manually (ie: nothing is holding on to it anymore) //reset hidden column values dgSponsors.Rows[_currentCell.RowIndex].Cells["colImageSelected"].Value = false; dgSponsors.Rows[_currentCell.RowIndex].Cells["colImageFilename"].Value = ""; } |
Can anyone help me troubleshoot this

DataGridViewCell holding on to image -- cannot delete