简体   繁体   English

我怎么知道datagridview列C#.net中显示哪个图像

[英]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. 我有一个datagridview,其中有2列,一列是文件的名称,另一列是具有图像的列,该图像可能具有红色或绿色图像。

I want to know how could I get the value to know which image is displayed in the datagridview column as follow: 我想知道如何获取值来知道在datagridview列中显示的图像,如下所示:

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: 并按如下方式加载到datagridview中:

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. 如果您告诉我们使用的是.NET Display技术,那将大有帮助。 Even how you display a boolean as a iamge can varry greatly between those, and so does the answer. 甚至您如何将布尔值显示为iamge也会在两者之间大相径庭,答案也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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