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

Posted on 2007-07-21
Last Modified: 2013-11-17
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!)

Question by:Pedraz
    1 Comment
    LVL 25

    Accepted 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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now