Solved

Referencing a cell's data without throwing an exception!

Posted on 2014-04-21
2
150 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

627 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