Al copiar fila seleccionada de DATAGRIDVIEW1 a DATAGRIDVIEW2 siempre copia la primera fila por default
Al copiar la fila seleccionada de DataGridView1 a DataGridView2 siempre copia la primera fila por default. Adjunto el código que utilizo y si pueden mejorarlo y corregirlo, le agradecería. Lo que debería de ejecutar el código es lo siguiente:
1° Buscar valor en DataGridView1 desde Textbox2
2° Seleccionar la fila del valor hallado en DataGridView1
3° Copiar la fila seleccionada a DataGridView2
4° Eliminar fila selecionada de DataGridView1
5° Retornar a TextBox2, limpiarlo y deseleccionar todo en DataGridView1
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress
For i As Integer = 0 To DataGridView1.Rows.Count - 2
For x As Integer = 0 To DataGridView1.ColumnCount - 1
If DataGridView1.Rows(i).Cells(x).Value.ToString.Contains(TextBox2.Text) Then
DataGridView1.CurrentCell = DataGridView1.Rows(i).Cells(x)
DataGridView1.Rows(i).Selected = True
For Each row As DataGridViewRow In DataGridView1.SelectedRows
Dim documento As String = row.Cells("Documento").Value
Dim denominación As String = row.Cells("Denominación").Value
Dim cantidad_de_pedido As String = row.Cells("Cantidad_de_pedido").Value
Dim material As String = row.Cells("Material").Value
DataGridView2.Rows.Add(documento, Denominación, Cantidad_de_pedido, Material)
Next
For Each r As DataGridViewRow In DataGridView1.SelectedRows
DataGridView1.Rows.Remove(r)
Next
DataGridView1.ClearSelection()
TextBox2.Text = ""
Exit Sub
End If
Next x
Next i
MsgBox("Error de Picking")
DataGridView1.ClearSelection()
TextBox2.Text = ""
End Sub