• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Dealing with null value cells in a datagridview

I have a datagridview with various columns - where one column has some data on a some rows - with most of the rows having no data ( null info).I want to read row by row skipping any row where the data is null.In VB6 I wrote if column = "" then -skip to next column. This does not work in VB8. Can anyone help please.
I have tried code like
"If Convert.ToInt32(Me.TransactDataGridView.Rows(i).Cells(1).Value.ToString()) = 0 Then"
-this does not work.
0
Lensulu
Asked:
Lensulu
  • 7
  • 5
1 Solution
 
AshokCommented:
Try

If (Me.TransactDataGridView.Rows(i).Cells(1).IsDbNull) Then

Ashok
0
 
AshokCommented:
Should this be also in Visual Basic.NET ZONE ?

Ashok
0
 
LensuluAuthor Commented:
My telesense does not pick up isdbnull. Am i missing a space import.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LensuluAuthor Commented:
My telesense does not pick up isdbnull. Am i missing a space import.I only need in vb net.
0
 
AshokCommented:
       Dim ob As Object = Me.TransactDataGridView.Rows(1).Cells(1)
        If (Convert.IsDBNull(ob)) Then

        End If

HTH
Ashok
0
 
AshokCommented:
      Dim ob As Object = Me.TransactDataGridView.Rows(i).Cells(1)
       If (Convert.IsDBNull(ob)) Then

       End If

HTH
Ashok
0
 
AshokCommented:
Could you add ZONE "Visual Basic.NET" to this question?

Ashok
0
 
AshokCommented:
This might be helpful.

http://www.freevbcode.com/ShowCode.asp?ID=5810

Ashok
0
 
LensuluAuthor Commented:
 Dim ob As Object = Me.TransactDataGridView.Rows(i).Cells(1)
            rbPayandDEp.Checked = True
            'here code for both

            counter = 0
            Do While i < rowcount - 1
                ' If (Me.TransactDataGridView{ColumnIndex=1,Rowindex=i} = "x" Then
                ' MsgBox(Me.TransactDataGridView.Rows(i).Cells(1).ToString)
                If (Convert.IsDBNull(ob)) Or (Me.TransactDataGridView.Rows(i).Cells(1).Value.ToString) = " " Then
                    Me.TransactDataGridView.Rows(i).Cells(1).Value = prefix + ((startnumber + counter).ToString)
                    'increment counter when found
                    counter = counter + 1
                 
                End If
             
                i = i + 1



            Loop
The above code does not code the blanks or null items.It just runs through without an error.

You asked me to include ZONE vbNet - how do i do that at this point. It is a Zone VB net problem.

Thansk
0
 
j-horbCommented:
If IsDBNull(Me.TransactDataGridView.Rows(i).Cells(1)) Then


End If
0
 
AshokCommented:
Dim ob As Object
            rbPayandDEp.Checked = True
            'here code for both

            counter = 0
            Do While i < rowcount - 1
                ' If (Me.TransactDataGridView{ColumnIndex=1,Rowindex=i} = "x" Then
                ' MsgBox(Me.TransactDataGridView.Rows(i).Cells(1).ToString)

                ob = Me.TransactDataGridView.Rows(i).Cells(1)

                If (Convert.IsDBNull(ob)) Or (Me.TransactDataGridView.Rows(i).Cells(1).Value.ToString) = " " Then
                    Me.TransactDataGridView.Rows(i).Cells(1).Value = prefix + ((startnumber + counter).ToString)
                    'increment counter when found
                    counter = counter + 1
                End If
                i = i + 1
            Loop

HTH
Ashok
0
 
LensuluAuthor Commented:
Thanks - I'm learning.first steps taken.

0
 
LensuluAuthor Commented:
Finally solved problem - thanks very much
Ashkok111.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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