[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

C++Builder 5.02 how to filter query results to display in DBAdvGrid?

C++Builder 5.02 / Windows XP
TMS Software (DBAdvGrid) to display a query (PobMod->PobQuery1)
(T_EMPLOYEE fields: C_CODE, E_ID, E_NAME,........................)
(T_ROOM fields C_CODE, E_ID, R_ROOM,.....)
The query is sorted by (SQL ->   ".....ORDER BY T_company.C_CODE, T_employee)
I have a boolean field to indicate if the person is on board or if he is at home
The grid, just now displays all the results and another information like the row number and the record number
The results for the query related to the persons on board are not more than 115 (that is the  total capacity of this ship) In the other hand the people moving around could be up to 300
As you can see it is not a big deal
I am using Borland Visual dBase 7.5 to create the tables and the query
I am looking how to filter the query result to display on the grid the following
1.- All the results
2.- The results filtered by the field C_CODE and/or C_COMPANY. So the user has the option to see only the personnel for a  company at a time in the dbgrid
Only for personnel on board, so the field E_ONBOARD is checked (true)
3.- All the results when E_ONBOARD is unchecked
4.- The above filtered by C_CODE or C_COMPANY
This is my first project on C++Builder and I am trying to create an application for a personal use and solve a lot of paperwork now keep it in another lot of folders created around the PC
Thanks a lot for any reply and allow me to continue (I am stuck!)

1 Solution
Take a look at the Filter and Filtered property of the query component.  These are common to all TDataSet related components including the query component.

Filtered is just a true/false to say the filtering is turned on or off.  

A Filter can be fairly complex with requirement for multiple fields,  and can be changed on the fly so you can easily alter the filter setting based on button press other user input.  The grid will show the current data view automatically.

So to see everything you can turn filtering off.

Then for each other condiditon set Filtered to true to turn filtering on.  Then build a string for the conditions of each data view you want.  So to show for a C_CODE and C_COMPANY values,

Filter = "C_CODE = '" + <some C_CODE value> + "' or C_COMPANY = '" + <some C_COMPANY value> + "'";

Now if you wanted to also do the E_ONBOARD,

Filter = "(C_CODE = '" + <value> + "' or C_COMPANY = '" + <value> "') and E_ONBOARD = 'true';

If your results are not exactly what you expect double check the logic in your filter.

Also take a look at FilterOptions property which allows for things like case sensitivity and some limited wildcard ability.

You can also use < and > conditions and have any number of combined condtions.  

Check out the help file for more info on the Filter property of TDataSet's.

Using the Filter directly like this is probably the easiest approach.   It works really well for small datasets and/or local database's.  If your datasets are really big then regeneration the query with the more specific request might be better.

If you need finer control there is also a OnFilterRecord event that you can use.  This allows you to write your own filtering code which can have pretty much any conditions you want.  This event will fire for each record in the dataset and return true or false with the Accept value.


Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now