Solved

VB 2008  - Is a DataGridView field null or empty?

Posted on 2009-07-10
11
454 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
  • 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Highfive Gives IT Their Time Back

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

13 Experts available now in Live!

Get 1:1 Help Now