1.11M Members

typeof(Image)

 
0
 

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

if(cell.Value.GetType()==typeof(Image))
{
    ......
    ......
}

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

 
0
 

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

 
0
 

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.

 
0
 

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 :)

 
0
 

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

Question Answered as of 2 Years Ago by skatamatic, jbrock31 and Mitja Bonca
 
0
 

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

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: