Datagridview Search

Posted on 2010-01-05
Last Modified: 2013-11-26
I am using a datagridview that I populate from the local machine's Outlook contacts. I am not currently using a dataset or table but populating the data directly from Outlook. This is all working fine. The datagridview contains a checkbox that I'll use to loop and perform some action with all the selected rows. My challenge is to add some intelligent search options to type a value into a text box and search the grid. If I do not get the right 'John' I would like to continue the search and move to the next 'John'
I got the first part working to some extend but need some help.
Current search Code snippet included under code
Dim x As Integer = 0

        While x < DataGridView1.Rows.Count

            Dim y As Integer = 0

            While y < DataGridView1.Rows(x).Cells.Count

                Dim c As DataGridViewCell = DataGridView1.Rows(x).Cells(y)

                If CType(c.Value, String) Is Nothing Then


                    If InStr(UCase(CType(c.Value, String)), UCase(TextBox2.Text)) Then

                        DataGridView1.Rows(x).Selected = True

                        DataGridView1.CurrentCell = DataGridView1.Rows(x).Cells(y)

                    End If

                End If

                System.Math.Min(System.Threading.Interlocked.Increment(y), y - 1)

            End While

            System.Math.Min(System.Threading.Interlocked.Increment(x), x - 1)

        End While

Open in new window

Question by:esps
    LVL 96

    Accepted Solution

    If you need to do a Find, and then a Find Next, I would think that you need to have a module-level variable for the row index, instead of a local variable (y).

    Author Closing Comment

    Thanks! It is the little things that makes us special :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now