Private Sub Dgv1_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles Dgv1.RowEnter
If e.ColumnIndex = 1 Or e.ColumnIndex = 0 Then
If Dgv1.CurrentRow Is Nothing Or e.RowIndex - 1 < 0 Then
Exit Sub
End If
Dim i As Integer = Dgv1.Rows(e.RowIndex - 1).Cells(0).Value
If i = 0 Then
Exit Sub
End If
Dim sqlstr As String = "Select Barcode,QtnName,Qtn From QtnTbl where Barcode=" & i
Dim dAdpt As New SqlClient.SqlDataAdapter(sqlstr, con)
Dim dt As New DataTable
dAdpt.Fill(dt)
If dt.Rows.Count > 0 Then
If Dgv1.CurrentRow Is Nothing Then
Exit Sub
End If
Dgv1.Rows(e.RowIndex - 1).Cells(1).Value = dt.Rows(0)(1).ToString
Dgv1.Rows(e.RowIndex - 1).Cells(2).Value = dt.Rows(0)(2).ToString
End If
End If
End Sub
Private Sub Dgv1_RowLeave(sender As Object, e As DataGridViewCellEventArgs) Handles Dgv1.RowLeave
If e.ColumnIndex = 1 Or e.ColumnIndex = 0 Then
Dim i As Integer = Dgv1.Rows(e.RowIndex).Cells(0).Value
If i = 0 Then
Exit Sub
End If
Dim sqlstr As String = "Select Barcode,QtnName,Qtn From QtnTbl where Barcode=" & i
Dim dAdpt As New SqlClient.SqlDataAdapter(sqlstr, con)
Dim dt As New DataTable
dAdpt.Fill(dt)
If dt.Rows.Count > 0 Then
Dgv1.Rows(Dgv1.CurrentRow.Index).Cells(1).Value = dt.Rows(0)(1).ToString
Dgv1.Rows(Dgv1.CurrentRow.Index).Cells(2).Value = dt.Rows(0)(2).ToString
End If
End If
End Sub