简体   繁体   English

隐藏DataGridViewImageColumn中的图像

[英]Hide images from DataGridViewImageColumn

I need to hide or show images for individual cells in a DataGridViewImageColumn. 我需要在DataGridViewImageColumn中隐藏或显示单个单元格的图像。 I put the code in cell formatting event. 我把代码放在单元格格式化事件中。 But I have no idea how to hide images from cells. 但是我不知道如何隐藏单元格中的图像。 The only way I know how to remove images would be first set the image column's Image property to null and then set each cell's image to some images for display. 我知道如何删除图像的唯一方法是,首先将图像列的Image属性设置为null,然后将每个单元格的图像设置为一些图像进行显示。 But this is a bit inconvenient because the image show/hide code is now in my cell formatting event. 但这有点不方便,因为图像显示/隐藏代码现在在我的单元格格式化事件中。

Anyone knows easy way to hide/remove images from individual cells? 有谁知道从单个单元格隐藏/删除图像的简单方法? Thanks. 谢谢。

I was just searching for the solution to the same problem and the one I've settled for the following: 我只是在寻找相同问题的解决方案,而我已经解决了以下问题:

if (showImage == true)
{
    imageCell.Value = new Bitmap(iconPath);
}
else
{
    imageCell.Value = new Bitmap(1, 1);
}

If the background of your cell is white the 1x1 bitmap won't be visible. 如果单元格的背景是白色,则1x1位图将不可见。 Otherwise you'll have to color that pixel according to your needs. 否则,您将不得不根据需要为该像素着色。

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

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