Ok so, I'm using a DBGrid that displays data from a database.
The database contains a table which contains 11 columns. Column number 4 is called customer name and contains name of customers.
I'd like a search box (similar to google search bar) where I would write in a client name I want Once I do that the DBGrid should change and display only the rows that contain that client name in the 4th column (column customer names)
Example:
Column names:
column1 - column2 - column3 - customer name - column5 - column6 - column7 - column8 - column9 - column10 - column11
blabla blabla blabla John Edwards blabla blabla blabla blabla blabla blabla blabla
blabla1 blabla1 blabla1 Michael Skunk blabla blabla blabla blabla blabla blabla blabla
blabla2 blabla2 blabla2 John Edwards blabla2 blabla2 blabla2 blabla2 blabla2 blabla2 blabla2
And so on.. lots of rows, all with different information in every column. At some point I will have in my database different information in the rest of the columns but the same client name in column number 4 (customer name column)
In my example, I already do, as you can see I have 2 entries for John Edwards
Subsequently when I write that customer name in the search field I'd like all those rows to display on the DBGrid while any other row that doesn't contain that name in column number 4 to dissapear
If using the above example, once I write John Edwards in the search field I should only see those 2 rows on the DBGrid
Once I clear the search field of what I wrote, the DBGrid should revert back to it's initial state and display everything, like it was before searching.
Any idea how to do this? I have no clue since I'm rather new to Delphi and searches both here and on Google haven't come up with anything useful / anything I can work with..
I would appreciate any help, thanks a lot!
TDataSet.Filter
andTDataSet.Filtered
, which will allow you to temporarily change what is displayed by filtering the data to only display content that matches the filter expression. There are examples both in the documentation and here on SO that show you how to filter data. You don't do it by the DBGrid; you do it by filtering the data itself. – Ken White