Ako Musha

Ako Musha

  • NA
  • 28
  • 12.2k

How to delete all the empty rows in a datagirdview?

Oct 26 2018 2:00 PM
I would like to delete the empty rows from a column. Here is what I've tried but does not work, I am getting an error as "use 'new' keyword to create an object instance"!
 
Your help would be appreciated, thanks so much.
 
 
  1. For i= data.Rows.Count - 1 To 0 Step -1  
  2.   
  3. Dim row As DataGridViewRow = data.Rows(i)  
  4.   
  5. if (Not row.IsNewRow Andalso data.Rows(i).Cells(1).Value.Tostring() = ""Then  
  6.   
  7. data.Rows.RemoveAt(i)  
  8.   
  9. Else  
  10. End If  
 

Answers (3)