Winforms 如何在Windows窗体中将不同的图像应用于DataGridViewImageColumn

Winforms 如何在Windows窗体中将不同的图像应用于DataGridViewImageColumn,winforms,image,datagridview,Winforms,Image,Datagridview,我使用的是DataGridView,我在其中动态创建了一个图像列,我想在该列中显示通过和失败的图像,具体取决于下面的代码条件 DataGridViewImageColumn img=新DataGridViewImageColumn() img.Name=“img”; img.HeaderText=“图像列”; dataGridView1.DataSource=dt; dataGridView1.Columns.Add(img); int number_of_rows=dataGridView1.

我使用的是DataGridView,我在其中动态创建了一个图像列,我想在该列中显示通过和失败的图像,具体取决于下面的代码条件

DataGridViewImageColumn img=新DataGridViewImageColumn()

img.Name=“img”;
img.HeaderText=“图像列”;
dataGridView1.DataSource=dt;
dataGridView1.Columns.Add(img);
int number_of_rows=dataGridView1.RowCount;
对于(int i=0;i<(行数-1);i++)
{
if(dataGridView1.Rows[i].Cells[2].Value.ToString()=“通过”)
{
Image=global::Instore.Properties.Resources.pass;
图像=图像;
dataGridView1.Rows[i]。单元格[“img”]。值=图像;
}
else if(dataGridView1.Rows[i].Cells[2].Value.ToString()=“Fail”)
{
Image image2=global::Instore.Properties.Resources.fail;
img.Image=image2;
dataGridView1.Rows[i]。单元格[“img”]。值=图像2;
}
}
我在运行代码时附加了代码,它在所有行中显示Pass.png,而在某些行中应该显示fail图像

请帮忙

谢谢
Sneha

删除这两行:

img.Image = image;

...

img.Image = image2;
img.Image = image;

...

img.Image = image2;