0

我正在使用 DataGridView ,我在其中动态创建了一个图像列,我想根据以下条件在此列中显示通过和失败图像是代码,

DataGridViewImageColumn img = new DataGridViewImageColumn();

                    img.Name = "img";
                    img.HeaderText = "Image Column";



                    dataGridView1.DataSource = dt;
                    dataGridView1.Columns.Add(img);

                    int number_of_rows = dataGridView1.RowCount;

                    for (int i = 0; i < (number_of_rows - 1); i++)
                    {
                        if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "Pass")
                        {

                            Image image = global::Instore.Properties.Resources.pass;
                            img.Image = image;
                            dataGridView1.Rows[i].Cells["img"].Value = image;

                        }
                        else if (dataGridView1.Rows[i].Cells[2].Value.ToString() == "Fail")
                        {
                            Image image2 = global::Instore.Properties.Resources.fail;
                            img.Image = image2;
                            dataGridView1.Rows[i].Cells["img"].Value = image2;


                        }
                    }

我在运行它时附加了代码,它在所有行中显示 Pass.png 而它应该在某些行中显示失败图像..

请帮助...

谢谢斯内哈

4

1 回答 1

1

删除这两行:

img.Image = image;

...

img.Image = image2;
于 2012-05-20T06:42:26.587 回答