0

i created a code where an item is searched in the datagridviw and when a user hits enter or down key the focus is set to the datagridview , I want the scroll staart from the selected row but it is starting from the last selected row.

my code :

  Private Function FindItems(ByVal strSearchString As String) As Boolean
    dgvsearchitem.ClearSelection()
 For Each myRow As DataGridViewRow In dgvsearchitem.Rows
        For Each myCell As DataGridViewCell In myRow.Cells
            If InStr(myCell.Value.ToString, strSearchString,CompareMethod.Text) Then
                myRow.Selected = True
                Return True
            End If
        Next
    Next
    Return False

End Function
 Private Sub txtitemsearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtitemsearch.KeyDown
    If (e.KeyCode = Keys.Enter Or e.KeyCode = Keys.Down Or e.KeyCode = Keys.Tab) And txtiname.Text <> "" Then
        dgvsearchitem.Focus()

    End If

End Sub
ravi sharma
  • 59
  • 1
  • 8

0 Answers0