Solved

Null Reference Exception?

Posted on 2008-09-30
6
355 Views
Last Modified: 2012-05-05
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,

0
Comment
Question by:kidl33t
  • 3
  • 3
6 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22608642
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
0
 

Author Comment

by:kidl33t
ID: 22608683
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.  
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 22609224
As far as the backup being three days out that should not be a problem just to get an idea what was changed.

The only other thing I can think of if you are using the class name to reference the controls of that form object you may try and pass to form 2 the reference from form 1 and see if that corrects the problem.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:kidl33t
ID: 22609500
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!
0
 

Author Closing Comment

by:kidl33t
ID: 31501682
Thanks mate, it was a perfect solution

0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 22609710
Not a problem, glad I was able to help.  ;=)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question