0

Hi!
I want to know, how to delete empty or blank row in DataGridView in Vb.net..........
"When i click Button the all empty or blank row in DataGridView will be remove......"
LIKE this :
" Before Button Clicked "
cccfb5927324360a697c76844a521720
" After Button Clicked "
be990ddb7744e1b53a444eeda94e8064

3
Contributors
4
Replies
35
Views
2 Years
Discussion Span
Last Post by hhm_pro992
2

Try

For r As Integer = dgvMyGrid.Rows.Count - 1 To 0 Step -1

    Dim empty As Boolean = True

    For Each cell As DataGridViewCell In dgvMyGrid.Rows(r).Cells
        If Not IsNothing(cell.Value) Then
            empty = False
            Exit For
        End If
    Next

    If empty Then dgvMyGrid.Rows.RemoveAt(r)

Next

You want to delete from the bottom to the top because if you delete from the top first then you end up changing the number of rows while the loop is executing.

0

As i can see here, you are directly adding/editing on your datagridview, right?, are you using Access, MySQL or SQL?

0

For all we know the OP could be using an unsourced DataGridView. Judging by the last picture I would imagine that AllowUserToAddRows is set to False otherwise there would be a blank (uncommitted) row displayed after the two records.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.