As far as i can understand, you are entering the values manually.
So when you enter enough values, you click on button or column header to sort the column.
Now i dont think that after you have added the last value you clicked any where else but directly went out for sorting.
If you click anywhere else, you will find that then also the extra row will be added.
Also the extra row will be added while sorting for the first time only.
This is happening because even when you enter the last value and click anywhere else, CellEndEdit event is called.
The following code might do the trick
Private Sub DataGridView1_CellEndEdit(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
DataGridView1.Rows.Add()
i = i + 1
DataGridView1.CurrentCell = DataGridView1(2, i)
End Sub
Private Sub DataGridView1_Sorted(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.Sorted
Dim totalRowContent As String
For rwNum As Integer = 0 To DataGridView1.Rows.Count - 1
If rwNum = DataGridView1.Rows.Count Then
Exit For
End If
totalRowContent = ""
For colNum As Integer = 0 To DataGridView1.Columns.Count - 1
totalRowContent = totalRowContent + DataGridView1(colNum, rwNum).FormattedValue
Next
If totalRowContent = "" Then
DataGridView1.Rows.RemoveAt(rwNum)
rwNum -= 1
End If
Next
End Sub
And remember, SendKeys is a very dangerous thing, avoid it as far as possible. You used SendKeys for calling the KeyPress event which in turn set the focus to the next desired cell.
I simplified it by setting the focus in CellEndEdit event only and I used the Sorted event of DGV to delete extra rows present.