Solved

Referencing a cell's data without throwing an exception!

Posted on 2014-04-21
2
143 Views
Last Modified: 2014-04-21
I have a DataGridView in which one of the checks I am trying to use is when the cursor is in the current cell, I need to check the value of the previous cell in the same row, however, when I try to do this I get the infamous "Object reference not set to an instance of an object" error.

I have attached the KeyUp Event in which this error is occurring. I have the line of code highlighted in yellow where this error occurs.
KeyUp-Event.docx
0
Comment
Question by:BlakeMcKenna
2 Comments
 
LVL 20

Accepted Solution

by:
Russ Suter earned 500 total points
ID: 40012838
You could certainly get that exception if you're trying to access cell index -1. The easiest way to avoid the problem is to add a null reference check. You can modify your highlighted line of code as follows:

If (not(strCellData is nothing) andalso strCellData.Length = 0) Then

Open in new window

0
 

Author Closing Comment

by:BlakeMcKenna
ID: 40012882
That worked!

Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now