Solved

Referencing a cell's data without throwing an exception!

Posted on 2014-04-21
2
142 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

11 Experts available now in Live!

Get 1:1 Help Now