I have a DataGridView that has an image
column. The image
address is read from one of the cells of the same row and then shown.
When I sort the columns the images go away.
I'm using Visual Studio 2010 and coding in C#. Data is retrieved from anaccess database using oledb methods.
Code that fills image
columns is below:
Image Image_File = Image.FromFile("d:\\2.jpg");
DataGridViewAutoSizeColumnMode.Fill;
for (int i=0;i < info_Grid.RowCount;i++)
{
if (Info_Grid.Rows[i].Cells[6].Value !=" ")
{
Image_File = Image.FromFile(Info_Grid.Rows[i].Cells[5].Value.ToString());
Info_Grid.Rows[i].Cells["Image_Col"].Value = Image_File;
}
}
Info_Grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
How can I fix it?
Thanks
I know this is old, but I was troubled by this this morning. When sorting a dataviewgrid, all the images added at runtime are lost. Something about the built-in DataGridView sorting breaks this.
Example
>>
For me, I just added my image add code to the DGV.
Sorted
event. It somehow feels wrong to have to do this, but I do not know why these images are lost on sort in the first place.