我创建了一个代码,其中在datagridviw中搜索项目,当用户点击enter或down键时焦点设置为datagridview,我想要从所选行开始滚动staart但是它从最后选择的行开始。
我的代码:
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