开发者

Hide images from DataGridViewImageColumn

I need to hide or show images for individual cells in a 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. But this is a bit inconvenient because the image show/hide code is now in my cell formatti开发者_开发问答ng 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. Otherwise you'll have to color that pixel according to your needs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜