because if I enter a new line in the datagridview, this is overwritten in the first line vb.net

I'm doing a point-of-sale system with barcode reader. The data that I upload to a datagridview, I add in the column "Quantity" articles with the same barcode, adds them automatically, but when reading another article with different code when you insert the first read into a new line, but if you add another article, write it in the first line of the datagridview. You can help me add some of the code for further explanation

Dim Row As Integer = 0
Dim i As Integer
Dim Amount As Integer = 0
Dim exists as Boolean = False





Private Sub txt_No_Factura_KeyPress (sender ByVal As Object, ByVal and As System.Windows.Forms.KeyPressEventArgs) Processes txt_No_Factura.KeyPress
Dim code as a string

If txt_No_Factura.Text <> "" "Then
Try it

If (e.KeyChar = (Convert.ToChar (Keys.Enter))) Then
Dim connection as SqlConnection
Connection = New SqlConnection ("Data Source = Gabriel-PC  SQLEXPRESS; Start Catalog = Sales; Integrated Security = True")
Open connection ()
Dim Code As String = txt_No_Factura.Text
Dim String As String = "Select Barcode, ID Product, Name, Sales Price from Product, where Barcode =" "& Cod &" "
Dim command as SqlCommand
Command = New SqlCommand (String, Connection)
Dim register as SqlDataReader
record = command.ExecuteReader ()
record.Read ()


cod_barra.Text = record (0)
txt_idproducto.Text = record (1)
txt_nombreProduct.Text = record (2)
txt_precioUnitario.Text = record (3)

datalistado.ColumnCount = 5
With datalistado
Columns (0) .Name = "Quantity"
.Columns (1) .Name = "Barcode"
.Columns (2) .Name = "Product Code"
.Columns (3) .Name = "Name"
.Columns (4) .Name = "Sell Price"
End with
Connection. Shut down ()

If datalistado.Rows.Count = Nothing Then
Amount + = 1
datalistado.Rows.Add ()
datalistado.Rows (f) .Cells (0) .Value = Quantity.ToString () - 1
datalistado.Rows (f) .Cells (1) .Value = cod_barra.Text
datalistado.Rows (f) .Cells (2) .Value = txt_idproducto.Text
datalistado.Rows (f) .Cells (3) .Value = txt_nombreProduct.Text
datalistado.Rows (f) .Cells (4) .Value = txt_precioUnitario.Text
= F = f + 1
txt_No_Factura.Text = ""
When

If datalistado.Rows.Count> 0, then
For line As Integer = 0 To datalistado.Rows.Count - 1
If datalistado.Rows (row) .Cells (1) .Value = cod_barra.Text Then & # 39; cod.toString ()
exists = true
else
is = wrong
When

Continue

When

If present = true then
= F = f + 1
Amount + = 1
datalistado.Rows (row) .Cells (0) .Value = (Quantity.ToString () - 1)
datalistado.Rows (row) .Cells (1) .Value = cod_barra.Text
datalistado.Rows (row) .Cells (3) .Value = txt_nombreProduct.Text
datalistado.Rows (row) .Cells (4) .Value = txt_precioUnitario.Text
txt_No_Factura.Text = "" & # 39; add this
= F = f + 1
When
If it exists = False Then
datalistado.Rows.Add (txt_cantiad.Text, cod_barra.Text, txt_idproducto.Text, txt_nombreProduct.Text, txt_precioUnitario.Text)
= F = f + 1
txt_No_Factura.Text = ""
When
When
Intercept Ex exception
MessageBox.Show ("The item was not registered when I entered the store")
Try the end


End If & if; end of if to confirm that the text is not empty x

End Sub