Whenever I have questions about how to do things in a DataGridView, I first turn to the Microsoft FAQ.
http://www.windowsclient.net/Samples/Go%20To%20Market/DataGridView/DataGridView%20FAQ.doc
In this situation, I usually do the processing of the CellFormatting event to set the image based on the value in the cell.
So, I would save my images as a list of images, and then the code in CellFormatting, as shown below:
private void dgv_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (dgv.Columns[e.ColumnIndex].Name == "status") { if (e.Value != null) { if (e.Value.ToString() == "1") { e.Value = imageList1.Images[1]; } else { e.Value = imageList1.Images[2]; } } } }
source share