Link to home
Start Free TrialLog in
Avatar of kidl33t
kidl33tFlag for Canada

asked on

Null Reference Exception?

Hello Experts,

I have a form (form1) which opens another form (say, form2).  Form2 then refers to a dataGridView on Form1, getting its .currentRow.Index property.  This has worked for a long time.

I recently changed something, which has broken it.  I get a null reference exception when I try to access the currentRow property of the dataGridView on Form1.  

Now, I've checked.  The dataGridView's currentRow property is set fine before I switch to form2.  I've inserted break points and checked it lots of times.  

I have also double checked that inside form two this is true:
     Form1.dataGridView.CurrentRow Is Nothing

The strange thing is,  it isn't nothing.  I can plainly see its loaded with data.  

I was making changes earlier, and I'm sure I just changed a property of the dataGridView, or the second form.  I have no idea what it might have been though.  Does anyone have any ideas?

Thanks in advance,

Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Hi kidl33t;

About the only thing that comes to mind is the Modifier property of the DataGridView was changed from Friend to say Private, check the DataGridView property window.

The other thing you can do if your project is under source control is to compare the current project with an earlier version in Source Control.

Fernando
Avatar of kidl33t

ASKER

FernandoSoto:

I checked the modifier already, it is still set to friend.

I have a backup, but its nearly three days old.  (Thats my fault though)

The odd thing is, in the first form I can access that index right before I launch into the second form, then its just not accessible.  Strangest thing.  
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kidl33t

ASKER

Fernando:

You got it!  I didn't realize what I had done.  Original, Form1 was the primary form.  When I had to add a login feature to the program, I made it the second form.  The login form instantiated form1, but I then destroyed the login form (and I would assume its variables).  I've got it all sewn up now!

Thanks!
Avatar of kidl33t

ASKER

Thanks mate, it was a perfect solution

Not a problem, glad I was able to help.  ;=)