I want to dynamically update a DataGridView based on a user entering in search terms in a text box, using LINQ.
In order to do this, I want what they enter to not have to perfectly match the string in the database, but for example if the company is 'Telexperts' and they type in 'Tele' in the text box, then it will return all companies that has 'Tele' in their name.
Here is some rough psuedocode:
Dim CompaniesSortedByTextBox = (From c As Company In db.Companies
Where c.CompanyName Contains SortByNameTextBox.Value
Select c).ToList
Edit: Glad to see this question took off with a good response. I've been following the answers provided, and right now I am using the Contains method, but am finding it to be very slow. I am changing the datasource based on when the textbox is changed, as follows:
Private Sub FilterDataGridView(sender As System.Object, e As System.EventArgs)
Handles FilterByCityBox.TextChanged
DataGridViewElements = (From c As Company In db.Companies Select c).ToList 'Reset it.
If (FilterByCityBox.Text <> "") Then
CompanyInfos = (From c As Company in db.Companies Where c.City.Contains(FilterByCityBox.Text)).ToList
End If
PUCOCompanyRegistry.DataSource = CompanyInfos
It works, but is very slow. It requires the user waiting a good amount of time (about a half a second) after every keystroke in the textbox.