Click here to Skip to main content
15,846,726 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

Do you have any idea on how to check if all the cells in a row is empty and how to remove it?

Sergey Alexandrovich Kryukov 3-Mar-13 23:26pm    
Row from what? What did you try?
Raja Soosai 4-Mar-13 1:52am    
please update your question.
Sandeep Mewara 4-Mar-13 3:01am    
This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

1 solution

check it

Sub CheckEmptyCellOnRowThenRemove()
        Dim rw As DataGridViewRow

        Dim rowToDelete As Int32

        If DataGridView1.RowCount > 1 Then
            For r = DataGridView1.RowCount - 2 To 0 Step -1
                rw = DataGridView1.Rows(r)
                rw.Selected = True
                Dim strCheck As String = ""
                For c = 0 To DataGridView1.ColumnCount - 1
                    If Not IsNothing(rw.Cells(c).Value) Then
                        strCheck = strCheck & rw.Cells(c).Value.ToString.Trim
                    End If
                If strCheck = "" Then
                    rowToDelete = Me.DataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected)
                    If rowToDelete > -1 Then
                    End If
                End If
                rw.Selected = False
        End If
    End Sub
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900