Need assistance with a DataGridView in vb.net

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,
mrotor
mainrotorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.