Making an Incremental Search

I had a datagridview(dgvName) that was primarily used to load data from a certain table of my database.Using the datasource option in my datagridview's properties, I choose the table and in the Column, I bound a certain column(Name)...Now I had also a TextBox(tboxSearch) which I want to use as a way to search the data of my dgvName..I want the seaching to be incrementally, that is, when I type a single letter in the textbox, say A, cell will point to Aaron and when I type Ab, it will point to Aban and so on.Anyway I am using visual studio.net 2005 edition..Can somebody help me please... thanks.


Answer this question

Making an Incremental Search

  • ChupaChupa

    someone please....

  • Darren Tao

    thanks nobugz, your code was doing well on my first datagridview(dgvPatients) of my first form...but unfortunately, on the other two forms(dgvAccounts,dgvPhysicians) it was giving me an "InvalidOperationException was unhandled" pointing to .Selected = true saying that "Current Cell cannot be set to invisible cell".Here's my code for the first form as you indicated.

    Private Sub tboxSearchPatient_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tboxSearchPatient.TextChanged

    Dim ix As Integer
    For ix = 0 To dgvPatients.RowCount - 1
    With dgvPatients.Rows(ix).Cells(0)
    If Not .Value Is Nothing AndAlso .Value.ToString() Like tboxSearchPatient.Text & "*" Then
    .Selected = True
    Exit For
    End If
    End With
    Next

    End Sub


    and for the second one:

    Private Sub tboxSearchPhysician_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tboxSearchPhysician.TextChanged
    Dim i As Integer
    For i = 0 To dgvDoctors.RowCount - 1
    With dgvDoctors.Rows(i).Cells(0)
    If Not .Value Is Nothing AndAlso .Value.ToString() Like tboxSearchPhysician.Text & "*" Then
    .Selected = True '
    this is where the exception was thrown.
    Exit For
    End If
    End With
    Next
    End Sub
     


  • maitung

    Change the if statement to
    if not .value is nothing andalso .visible andalso .value.tostring...



  • keithster

    Set the DataGridView's MultiSelect property to False and use Option Compare Text. Then write a TextBox1_TextChanged event handler like this:

    Dim ix As Integer

    For ix = 0 To DataGridView1.RowCount - 1

    With DataGridView1.Rows(ix).Cells(0)

    If Not .Value Is Nothing AndAlso .Value.ToString() Like TextBox1.Text & "*" Then

    .Selected = True

    Exit For

    End If

    End With

    Next




  • Busy

    Make sure the DataGridView's MultiSelect property is False. Set a breakpoint on the .Selected = True statement and verify that it gets executed...


  • David B.

    there is no exception by now, but it seems that the datagridview was not behaving what it should be.It doesn't point to the row based on the text of the textbox...what could be possibly wrong

  • Making an Incremental Search