Solved

Determine If Row Is Empty in Datagridview

Posted on 2006-11-14
3
196 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
[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
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

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!

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…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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