Hi pmak,
To make the datagridview scroll to the page with the found record, you can set DataGridView.FirstDisplayedScrollingRowIndex Property or DataGridView.FirstDisplayedCell Property. However, to find the record in DataGridView, I prefer to use the BindingSource.Find method. See my sample below:
Code Snippet
Class DGVSearchItem
Private dt As New DataTable()
Private bs As New BindingSource()
Private Sub DGVSearchItem_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
dt.Columns.Add("fldID")
dt.Columns.Add("fldName")
For i As Integer = 0 To 49
dt.Rows.Add(i.ToString(), "Name" + i.ToString())
Next
bs.DataSource = dt.DefaultView
Me.DataGridView1.EditMode = DataGridViewEditMode.EditOnF2
Me.DataGridView1.DataSource = bs
Me.DataGridView1.AllowUserToAddRows = False
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Me.dataGridView1.BindingContext(bs).Position = bs.Find("fldID", Me.textBox1.Text)
End Sub
Class
Hope this helps.
Regards |