Solved

VB 2008  - Is a DataGridView field null or empty?

Posted on 2009-07-10
11
459 Views
Last Modified: 2012-05-07
If a grid field does not contain data then Completed = False.  The fields to be tested may contain text, a numeric, a date, or nothing at all.  It is possible that some data was entered into one of the fields and then removed by the user.

How can I test that a Value exists?  The design-time compiler does not like the following statement.

If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = Nothing Then Completed = False
0
Comment
Question by:ljcor
[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
  • 5
  • 5
11 Comments
 
LVL 9

Expert Comment

by:wellhole
ID: 24826850
You will want to use "is nothing" instead of "= nothing".
0
 

Author Comment

by:ljcor
ID: 24826902
Unfortunately, it does not like  IsNothing  either.
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826907
2 words.......
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:ljcor
ID: 24826974
It doesn't like that either:  two words, two errors.

IS says: Expression expected

NOTHING says: Illegal call expression or index expression
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826983
Please post your code after the modification.
0
 

Author Comment

by:ljcor
ID: 24826994
       Dim Completed As Boolean = True
        For i As Integer = 0 To 8
            If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = Is Nothing() Then Completed = False
        Next
        If Completed = False Then
            Call MsgBox("You cannot SELECT a Project until these data entry items are completed.  ", vbOKOnly + vbCritical + vbApplicationModal + vbDefaultButton1, "UNFINISHED DATA ENTRY")
            Exit Sub
        End If
0
 
LVL 9

Expert Comment

by:wellhole
ID: 24826995
REMOVE = and Nothing() is not a function so remove ()
0
 
LVL 3

Expert Comment

by:jbeasle3
ID: 24826996
Try this:
 
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = String.Empty Then Completed = False
OR
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = "" Then Completed = False
0
 

Author Comment

by:ljcor
ID: 24827048
I edited the data out of one of the fields:  The runtime error is:
   "Operator '=' is not defined for type 'DBNull' and string ""."
0
 
LVL 9

Accepted Solution

by:
wellhole earned 500 total points
ID: 24827069
Use isdbnull(EvalItemsDataGridView.CurrentRow.Cells(i).Value()) instead of comparing against an empty string.
0
 

Author Closing Comment

by:ljcor
ID: 31602249
YES!!  That worked perfectly.  Thanks for your help.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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 was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
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…

734 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