Solved

Referencing a cell's data without throwing an exception!

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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