Start New Discussion within our Software Development Community

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??

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

This question has already been answered. Start a new discussion instead.