Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Referencing a cell's data without throwing an exception!

Posted on 2014-04-21
2
Medium Priority
?
152 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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