Solved

Determine If Row Is Empty in Datagridview

Posted on 2006-11-14
3
190 Views
Last Modified: 2010-04-23
How do you determine if an entire row is empty?

The code below is not working well.  Even if there is one row of data it has two blocks of text output.

                If IsDBNull(datagrid1.Item(0, r).Value) = False And IsDBNull(datagrid1.Item(1, r).Value) = False And IsDBNull(datagrid1.Item(2, r).Value) = False And IsDBNull(datagrid1.Item(3, r).Value) = False And IsDBNull(datagrid1.Item(4, r).Value) = False Then
                    strTransportSequence &= CurRowStr & "     ==============================" & vbCrLf
                End If



            For r As Integer = 0 To datagrid1.Rows.Count - 1
                Dim CurRowStr As String = ""
                CurRowStr = CurRowStr & "     Test1 : " & datagrid1.Item(0, r).Value & vbCrLf
                CurRowStr = CurRowStr & "     Test2 : " & datagrid1.Item(1, r).Value & vbCrLf
                CurRowStr = CurRowStr & "     Test3 : " & datagrid1.Item(2, r).Value & vbCrLf
                CurRowStr = CurRowStr & "     Test4 : " & datagrid1.Item(3, r).Value & vbCrLf
                CurRowStr = CurRowStr & "     Test5 : " & datagrid1.Item(4, r).Value & vbCrLf
                If IsDBNull(datagrid1.Item(0, r).Value) = False And IsDBNull(datagrid1.Item(1, r).Value) = False And IsDBNull(datagrid1.Item(2, r).Value) = False And IsDBNull(datagrid1.Item(3, r).Value) = False And IsDBNull(datagrid1.Item(4, r).Value) = False Then
                    strTransportSequence &= CurRowStr & "     ==============================" & vbCrLf
                End If
            Next
0
Comment
Question by:endrec
3 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 350 total points
ID: 17943032
If I've understood correctly, what you want is this

            For r As Integer = 0 To datagrid1.Rows.Count - 1
                Dim CurRowStr As String = ""
                If IsDBNull(datagrid1.Item(0, r).Value) = False And IsDBNull(datagrid1.Item(1, r).Value) = False And IsDBNull(datagrid1.Item(2, r).Value) = False And IsDBNull(datagrid1.Item(3, r).Value) = False And IsDBNull(datagrid1.Item(4, r).Value) = False Then
                    strTransportSequence &= CurRowStr & "     ==============================" & vbCrLf
                Else
                    CurRowStr = CurRowStr & "     Test1 : " & datagrid1.Item(0, r).Value & vbCrLf
                    CurRowStr = CurRowStr & "     Test2 : " & datagrid1.Item(1, r).Value & vbCrLf
                    CurRowStr = CurRowStr & "     Test3 : " & datagrid1.Item(2, r).Value & vbCrLf
                    CurRowStr = CurRowStr & "     Test4 : " & datagrid1.Item(3, r).Value & vbCrLf
                    CurRowStr = CurRowStr & "     Test5 : " & datagrid1.Item(4, r).Value & vbCrLf
                End If
            Next

Roger
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

18 Experts available now in Live!

Get 1:1 Help Now