I have a field DataGridViewImageColumn
, and for each line of the field, depending on a condition, I add a different image. Anyone know how I can do this in Windows Forms?
if (dgvAndon.Rows[e.RowIndex].Cells["urgencyOrder"].ToString() == "1")
{
//Here I want to add the image in the image property field DataGridViewImageColumn.
}
use this code:
DataGridViewImageColumn iconColumn = new DataGridViewImageColumn();
iconColumn.Name = "AirplaneImage";
iconColumn.HeaderText = "Airplane Image";
dataGridView1.Columns.Insert(5, iconColumn);
for (int row = 0; row < dataGridView1.Rows.Count - 1; row++)
{
Bitmap bmp = new Bitmap(Application.StartupPath + "\\Data\\AirPlaneData\\" + dt.Rows[row][4]);
((DataGridViewImageCell)dataGridView1.Rows[row].Cells[5]).Value = bmp;
}
DataGridViewImageColumn
in your DataGridView
Add image this way:
for (int row = 0; row <= [YourDataGridViewName].Rows.Count - 1; row++)
{
((DataGridViewImageCell)gvFiles.Rows[row].Cells[1]).Value = Properties.Resources.Picture1
}
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