Searching through a datagridview with a textbox

Jiggerman75

Member
Joined
May 12, 2008
Messages
5
Programming Experience
Beginner
Hello

I am trying to search a name of a customer in a datagridview through a textbox but i have this code

Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
Dim i As Integer



If DataGridView1.CurrentRow.Cells.Item(0).Value = txtsearchcustomer.Text Then
For i = 0 To CustomerBindingSource.Count - 1
Next
Exit Sub

End If

CustomerBindingSource.MoveNext()



End Sub

all this is doing is allowing me to search manualy by pressing the search button untill i reach the desired result

please could someone help me solv this matter as i am starting to stress out
 
The form I used contained a textbox and a combobox. The cbox was used to select the column, and, as the user typed in the tbox, the matches were filtered as they typed. The code I used for this is listed below.

VB.NET:
    Private Sub TBCHSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TBCHSearch.TextChanged

        Me.CHTableAdapter.Fill(Me.GalvestonDataSet.CH)
        CHDataGridView.BringToFront()
        CHDataGridView.Refresh()
        If conn.State = ConnectionState.Open Then
            conn.Close()
        End If
        conn.ConnectionString = ConnectionString
        conn.Open()
        Dim da As New SqlDataAdapter("SELECT * FROM CH WHERE " + CBCHColumn.Text + " LIKE '" + TBCHSearch.Text + "%';", conn)
        Dim ds As New DataSet("CH")
        da.Fill(ds, "CH")
        CHDataGridView.DataSource = ds.Tables("CH").DefaultView
    End Sub

There may be more there than would be necessary, but I had to do a few things to make it compatible with my code.
 
Back
Top