locked
finding data in datagridview

    Question

  • hello,

     

    i have a question about datagridview.

    I built up my table and showed it in datagridview. Now i'd like to find any data in it. It's a table consist of strings. I have a textbox and i'd like to find the textbox1.text in the datagridview and select it, scroll to it. How could i achieve this?

     

    Thnx a lot

    Friday, July 13, 2007 5:28 PM

Answers

  • I'm sorry if it is not the answer that you want ,
    but i hope it still can help.

    I using this code for filter the name  Field in my Grid.

    example :
    you wrote "david" in text box
    the grid will diplay all name with the first name "David"

    PRIVATE BIND AS NEW BINDINGSOURCE
        Private Sub GetData(ByVal selectCommand As String)

            Try
                Me.PencarianAdapter = New MySqlDataAdapter(selectCommand, MyCN)
                ' Populate a new data table and bind it to the BindingSource.
                Dim PencarianDt As New DataTable
                Me.PencarianAdapter.Fill(PencarianDt)

                Me.BIND.DataSource = PencarianDt

                Me.DGPencarian.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells)
                Me.DGPencarian.RowHeadersWidth = 60


            Catch ex As MySqlException
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Grid")
            End Try

        End Sub

      Private Sub frmPencarian_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    'BIND IS BINDING SOURCE YOU MUST DELCARE FIRST
            Me.DGPencarian.DataSource = BIND
            GetData("Select nim,nama from data_pribadi")
        End Sub

        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    getData("Select nim as NIM,nama as Nama from data_pribadi where nama Like '" & Me.TextBox1.Text & "%'")


       End Sub



    Saturday, July 14, 2007 2:41 AM