• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

Datagridview Search

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
                Else
                    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

0
esps
Asked:
esps
1 Solution
 
Bob LearnedCommented:
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).
0
 
espsAuthor Commented:
Thanks! It is the little things that makes us special :)
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now