0

Hi friends)
I have such error in my code-

Object reference not set to an instance of an object

code -

int n1, n2;
if (dataGridView1[2, 0].Value != "") 
[B]if (int.TryParse(dataGridView1[2, 0].Value.ToString(), out n1) == false)[/B]{}

If I do not specify the value of the cell - this code will not work ..... I do not understand, why? (if to specify - it will work)
why it's so?
And I don't understand - why the code continues to run after the test -

if (dataGridView1[2, 0].Value != "")

Big thanks in advance)))

2
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by vedro-compota
1

You should use this:

if (string.IsNullorEmpty(dataGridView1[2, 0].Value))

Are you sure the 'row' or 'cell' you are referring; exists, when you run the code ????

Votes + Comments
+++++++++++
0

yea, because I initialize dVG within the form loading) thank you!))

Is your issue resolved ???
If NO, can you give more details like error messages etc.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.