简体   繁体   中英

How could I know which image is displayed in datagridview column C# .net

I have a datagridview which has 2 columns, one is the name of the file and the other one is a column that has image that could have a red or green image.

I want to know how could I get the value to know which image is displayed in the datagridview column as follow:

Note: By Default is red, but it will change to green once you do something with that file.

带有红色图像的图像

带有绿色图像的图像

How I added those images was with a image list as follow:

ImageList icons = new ImageList();
icons.Images.Add(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
    "..\\..\\images", "red.png")));
icons.Images.Add(Image.FromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
    "..\\..\\images", "green.png")));

and are loaded to the datagridview as follow:

foreach (string file in Directory.GetFiles(
    Path.Combine(DataBaseConfiguration.WPRPath, "CR" + _number)))
{
    if (!file.Contains("~$"))
    {
        dgvWprFiles.Rows.Add(new object[] { Path.GetFileName(file), icons.Images[0] });
    }
}

Well, the exactly question is: how to know when the column has red or green image?

thanks.

Those green and red images are most likely representing a Boolean value. You should be working with that Boolean value, not trying to re-verse engineer it via the image!

Unless you are doing screen scraping/atomation, you should not care what image is dispalyed. That is a minor detail of the Display side. And if you are doing screen scraping then the question should be rewored accordingly.

It would help a ton if you told us wich .NET Display technology you are a using. Even how you display a boolean as a iamge can varry greatly between those, and so does the answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM