We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,894 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

typeof(Image)

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

5
Contributors
5
Replies
2 Days
Discussion Span
1 Year Ago
Last Updated
6
Views
Question
Answered
cool_zephyr
Junior Poster in Training
84 posts since Apr 2009
Reputation Points: 5
Solved Threads: 10
Skill Endorsements: 0

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

Mitja Bonca
Posting Maven
2,561 posts since May 2009
Reputation Points: 642
Solved Threads: 486
Skill Endorsements: 13

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.

jbrock31
Junior Poster in Training
79 posts since Oct 2008
Reputation Points: 22
Solved Threads: 16
Skill Endorsements: 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 :)

skatamatic
Posting Shark
986 posts since Nov 2007
Reputation Points: 403
Solved Threads: 132
Skill Endorsements: 1

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

cool_zephyr
Junior Poster in Training
84 posts since Apr 2009
Reputation Points: 5
Solved Threads: 10
Skill Endorsements: 0
Question Answered as of 1 Year Ago by skatamatic, jbrock31 and Mitja Bonca

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

vimit
Newbie Poster
14 posts since Jan 2012
Reputation Points: 10
Solved Threads: 2
Skill Endorsements: 0

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0716 seconds using 2.66MB