Utkarsh Agrawal Utkarsh Agrawal - 1 year ago 97
Vb.net Question

Deleting Datagridview rows using LOOP

My Data Grid View Contains One Column.
Many Rows of

are empty I am using Loop to remove those rows.

For j = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(j).Cells(0).Value.ToString.Length = 0 Then
End If

Error : Index was out of range. Must be non-negative and less than the
size of the collection.

Thanks in Advance!

Answer Source

or you can just loop from the last row:

For j = DataGridView1.RowCount - 1 To 0 Step -1
    If DataGridView1.Rows(j).Cells(0).Value.ToString = "" Then
    End If
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download