Hi, You can implement the cell paint event. I think that you have a data table like this: (Val1, Val2, PicturePath, ...). You can find bellow an example of code that shows in a data grid view a grid contact: ---------------------------------------------------------------- |Picture | First Name | Last Name | Phone number | ---------------------------------------------------------------- | ;) | Mr. X | X1 | 00112233 | ---------------------------------------------------------------- | ;) | Mr. X | X1 | 00112233 | ----------------------------------------------------------------
// Subscribe to the event cell painting
myDataGridView += new DataGridViewCellPaintingEventHandler(myDataGridView_CellPainting);
// Implement the event
void myDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
// Test if you are drawing the picture cell. Note that the RowIndex == 0 is the row header
if (e.RowIndex > 0 && e.ColumnIndex == 0)
{
try
{
string strPath = myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
// To optimize you program, you can store the loadeds picture in a dictionary like this:
Bitmap objPicture = null;
if(dicPictures.ContainsKey(strPath))
{
objPicture = dicPictures[strPath];
}
else
{
objPicture = Bitmap.FromFile(strPath);
dicPictures.Add(strPath, objPicture);
}
e.Graphics.DrawImage(objPicture, e.CellBounds);
}
catch (Exception Error)
{
// Error Log or Managing
}
}
}