Sufvan Adil 2023 wrote:
If DataGridView1.Rows.Count - 1 Then
Thanks to VB's "evil type coercion", that condition will be False if you have precisely one row in your grid. For any other number of rows, that condition will be True.
Sufvan Adil 2023 wrote:
For i = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(i).Cells("d1alisname").Value = "" Then
Exit Sub
Else
DataGridView1.Rows.Add()
End If
Next
That code walks through all the rows in your grid until it finds one where the d1alisname column is blank. For every row that it encounters where that column is not blank, it adds a new row. You haven't explained exactly what you're trying to do. At a guess, you want to add a new row if there are either no rows in the grid, or all of the rows have a value in the d1alisname column. In which case, you need to move the "add row" code after your For loop from your second code block:
For i = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(i).Cells("d1alisname").Value = "" Then
Exit Sub
End If
Next
DataGridView1.Rows.Add()
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer