Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

VB 2008 - Is a DataGridView field null or empty?

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
ljcor
Asked:
ljcor
  • 5
  • 5
1 Solution
 
wellholeCommented:
You will want to use "is nothing" instead of "= nothing".
0
 
ljcorAuthor Commented:
Unfortunately, it does not like  IsNothing  either.
0
 
wellholeCommented:
2 words.......
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ljcorAuthor Commented:
It doesn't like that either:  two words, two errors.

IS says: Expression expected

NOTHING says: Illegal call expression or index expression
0
 
wellholeCommented:
Please post your code after the modification.
0
 
ljcorAuthor Commented:
       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
 
wellholeCommented:
REMOVE = and Nothing() is not a function so remove ()
0
 
jbeasle3Commented:
Try this:
 
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = String.Empty Then Completed = False
OR
If EvalItemsDataGridView.CurrentRow.Cells(i).Value() = "" Then Completed = False
0
 
ljcorAuthor Commented:
I edited the data out of one of the fields:  The runtime error is:
   "Operator '=' is not defined for type 'DBNull' and string ""."
0
 
wellholeCommented:
Use isdbnull(EvalItemsDataGridView.CurrentRow.Cells(i).Value()) instead of comparing against an empty string.
0
 
ljcorAuthor Commented:
YES!!  That worked perfectly.  Thanks for your help.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now