hello, i'm trying to check if a cell in datagridview is of type Image with the following code


but it's always showing "Object reference not set to an instance of an object" error..could anytell me if i'm doing this right?? If not, how do we check if the cell contains objects of image type??

Did you set the column to be type of Image in the 1st place?

Seems like there is not a value in the cell, thus the object reference error. Debug and verify there is a value there.

Also Mitja's response is important as well.

Although this probably doesn't help your problem, there is a shorthand in c# for exactly what you are doing

if (cell.Value is Image)
{ ... }

Edit: I looked it up and your method actually runs faster. But if performance isn't what you're after then this is a handy shorthand :)

thank you guys..after all there was no value in the cell..i've been able to fix the problem now

you must specify the cell index, in which image is stored.