DataGridViewImageColumn - disposing of all rows

Explosion_Of_Colour

New member
Joined
Feb 25, 2009
Messages
2
Programming Experience
3-5
Hi folks,

I'm sure I'm missing something here, but I don't know DataGridViews very well so if someone can help :eek:)

I have a gridview where ALL cells have a value that is an image from the filesystem, but I need to access these files for a certain function and so I've been trying to create a method that disposes of all these images thereby freeing them up on the filesystem (was received permission denied errors). The following loop worked for the first row of images but I can't work out how to do it for all rows:

VB.NET:
For Each c As DataGridViewImageColumn In dGV.Columns
    c.Image.Dispose()
Next

Ideas?
Thanks alot,
Becky
 
But you're not disposing the images in the cells. You're only looping through the columns, so you're only going to dispose one image per column. If you want to dispose images in every row then you have to loop through the rows too:
VB.NET:
For Each row As DataGridViewRow In Me.DataGridView1.Rows
    For Each cell As DataGridViewCell In row.Cells
        DirectCast(cell.Value, Image).Dispose()
    Next
Next
 
Back
Top