I created a form with datagridview for a list of clients. Now, I want to add a Search funtionality for my list, so that the user can just type in the value he wants to see and the row with that value will get selected. Also, I want to add a combobox wherein the user can choose what kind of filter he wants to apply to the Search function (by date, by number, by name...). And I also want the search queries to be non specific and not case-sensitive (I mean if I want to look for the name 'Sarah Jane', and I typed 'ah j', 'Sarah Jane' will still appear). How do I do it correctly? Is it even possible?

2 Years
Discussion Span
Last Post by airhalynn101

You can try this as a possible solution.

Dim nwData as CustomersDataSet = CustomersDataSet.GetCustomers()
m_CustomersGrid.DataSource = m_CustomersBindingSource
m_CustomersBindingSource.DataSource = nwData.Customers

Then you can sort using the BindingSource.

CustomersBindingSource.Sort = "ContactName ASC"

And you can find using the BindingSource.

Dim index as integer = _
CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
If index <-1 then 'it was found; move to that position
CustomersBindingSource.Position = index
End If

You could then populate:

CustomersBindingSource.Find("CompanyName", CompanyNameTextBox.Text)
with the keys pressed in the cell by capturing them by utilizing:

    Private Sub DataGridView1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyUp
            Dim dgv As DataGridView = TryCast(sender, DataGridView)
           If dgv IsNot Nothing Then
           'You will need some logic here to determine how long to wait between keyups 
           'Perhaps a timer that ticks every500 milliseconds and reset on keyup.  
            End If
        End Sub

I'm sorry but all those BindingSource things confuse me, but I got a solution for this problem. What I did was to requery (or re-populate?) my datatable based on the string in the textbox (on textchanged event) using
select * from tablename where column like '%" & textbox1.text & "%'"
(or something like that)

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.