简体   繁体   中英

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 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. Otherwise you'll have to color that pixel according to your needs.

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