Steve
Steve

Reputation: 5073

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.

Upvotes: 3

Views: 4496

Answers (1)

mrt
mrt

Reputation: 1739

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.

Upvotes: 8

Related Questions