I have a DataGridView
with an image column. In the properties, I am trying to set the image. I click on image, choose the project resource file, and then select one of the images displayed. However, the image still shows as a red x on the DataGridView? Anybody know why?
For example you have DataGridView control named 'dataGridView1' with two text columns and one image column. You have also an images in resource file named 'image00' and 'image01'.
You can add images while adding rows like this:
dataGridView1.Rows.Add("test", "test1", Properties.Resources.image00);
You can also change image while your app is running:
dataGridView1.Rows[0].Cells[2].Value = Properties.Resources.image01;
or you can do like this ...
void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "StatusImage")
{
// Your code would go here - below is just the code I used to test
e.Value = Image.FromFile(@"C:\Pictures\TestImage.jpg");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With