Ok I have a program that contains a datagridview control linked to a database and i want to be able to search through every field via a ButtonSearch for a match of the search term - search term is entered in a text box labeled search - and display only the records that have a match in the datagridview.
Just semantics/terminology but something to keep in mind, a datagridcontrol doesnt actually hold the data or connect directly to a database, you assign it a datasource such as a dataset/datatable etc... The underlying datasource is what you want to search & filter.
To answer your actual question, take a look at "DataView.RowFilter" in the help index. It will show you how to filter the data in your dataset/datatable and has an example. If you still need help just let me know.
Thanks for the help, but the help only seems to describe an example where the field to be searched is specified.
In my case, I need to be able to search through every field on the form for a term as it may be in any field.
I can successfully filter the datagridview using SQL and searching all records by one field, I want to search all records by all fields.. sorry hard to explain..
My query was
UpdateGrid("SELECT * FROM TrackTable WHERE * = '" & txtSearch.Text & "' ORDER BY ArtistName ASC")
Unfortunately, VB doesn't accept the second "*" .. says a parameter is missing. I replaced it with a list of all column names, separated by "OR". This didn't show up any errors when debugging, but it seemed to be doing absolutely nothing on the form. nothing happened.
You have to specify every single field that you want to search. You also have to specify if your looking for an exact match or perhaps one word (or even part of a word) within an individual field. For instance
Where Column1 Like '%mySearchText%'
Or Column2 Like '%mySearchText%'
The percent sign is a wild card telling it I dont care what letters/words are before or after my search text within that field. For exact matches you can simply use the equals sign followed by your search word(s).
Obviously that is if your are filtering during your actual query. To filter an already filled datatable, the method I mentioned earlier still applies. And yes you can add more then one column to be searched with that method. However searching every field is very process intensive I would suggest letting your database do that type of filter.
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...