I have created a DataGridViewImageColumn and want to perform operation if the value of the image cell is green check box image.
The code is given below. But its not going inside the condition
if (dgvException.Rows[e.RowIndex].Cells["colStock"].Value
== Properties.Resources.msQuestion)
{
//Some code
}
Please help.
Checking equality for images using the equality operator (
==) doesn’t work the way you need it to work. That’s why with your equality check always returns false.You need to find out if the content of two images are the same — to do this you’ll need to do a pixel by pixel check of the image in the DGV cell and the reference image. I found a few links to this article that demonstrates comparing two images. I’ve taken the image comparison algorithm from the article and condensed it into a method that takes two
Bitmapsto compare as parameters and returns true if the images are identical:(warning: code not tested)
Using this method your code becomes: