Need assistance with a DataGridView in

Hi Experts -
I need help adding a search feature (could be a textbox), in my vb.Net project, to search for a given record in my DataGridView.  When my app first loads, it loads approx. 35,000 records to my DataGridView.   Users are having a difficult time scrolling through all those records.  I need to give them the ability to enter an given loan number on a textbox, and then be able to jump to the desired load on the DataGridView.  How can I do this?

Thanks in advance,
Who is Participating?
Fernando SotoConnect With a Mentor RetiredCommented:
Hi mainrotor;

Having a text box on the form and a button to execute the search the following code snippet will do what you need.

Private Sub FindRow_Click(sender As Object, e As EventArgs) Handles FindRow.Click

    ' Convert the text box data to the correct DataType
    ' In this case to an Integer
    Dim cid = Integer.Parse(TextBox1.Text)

    ' Create a Linq query to find the row you wish to view
    ' In this case I am looking for the column CustomerID 
    ' that has the value cid and return the first row
    Dim row = (From r As DataGridViewRow In DataGridView1.Rows
               Where r.Cells()("CustomerID").Value = cid
               Select r).FirstOrDefault()

    ' Check to see if the row was found if so scroll the row to the 
    ' first viewable row 
    If row IsNot Nothing Then
        DataGridView1.FirstDisplayedScrollingRowIndex = row.Index
    End If

End Sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.