Solved

Determine If Row Is Empty in Datagridview

Posted on 2006-11-14
3
189 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Query datatable in LINQ 6 39
Performance enhancement 39 25
Merging PDFs with VB.NET 10 30
Total in textboxes 9 35
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
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…

744 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

17 Experts available now in Live!

Get 1:1 Help Now