Question:
I would like to have my grid keep track of information with two checkboxes. There is no data in the physical table that stores this.
First Checkbox – Archive Record
Second Checkbox – Recalculate Totals before Archive.
I have a Query with joins on multiple tables displaying information in a TwwDBGrid and yields a read only result. Unfortunately the grid will allow allow me to use one column to multi-select. I need more than one. Is there a way to achieve this?
I have tried adding 2 dummy fields in the query – without success. The CheckBoxes are displayed in the grid, but they don’t change when clicked on
Eg. SELECT 0 AS CBX1, 0 AS CBX2 from TABLE1 LEFT JOIN TABLE2.
The Checkbox would be used as a record marker only to indicate Archiving and Recalculation.
Answer:
You can create extra fields in your query (that are not in the database) using ‘select 0 as checkbox1’, etc. Then these fields should be accessible to the grid. You will need to configure the dataset so it is editable so that the grid can toggle their checkbox. So do the following.
- Set your Cachedupdates property of your query to true.
- Set the readonly to false for your checkbox TField in your query dataset.
- When configuring it as a checkbox in the grid (dbl-click the grid to configure the column), make your true/false values match the data type. If it is an integer, make it 1 for true and 0 for false.
I tried this and it seems to work.
Comments
2 comments
Hi Roy, I tried your solution, But I still seem to be missing something.
SELECT TransID, CAST(0 AS BIT) AS RECALC, C.CUSTFSTNAME + ' ' + C.CUSTLSTNAME AS CUSTNAME FROM TABLE1 LEFT JOIN TABLE2.
I combined the "Selected" Boolean field (as the first Check box). Is this the way you tested it?
Or did you use 2 extra fields in the query and exclude the "Selected" Boolean field?
What datatype did you specify in your select statement?
Also this is on Infopower4000VCL6 and BDE 5.2. (in the process of converting the project)
In my case I have the following query in TFDQuery
select 0 as cb1, 0 as cb2, * from fdcustomer
I made the query editable by setting cachedupdates to true. I then right-clicked the tfdquery to bring up the tfields editor. I added all the fields and made the cb1 and cb2 fields readonly to false. I then dbl-clicked the grid and in the cb1 and cb2 column's I configured the control type as checkboxes. I made the true value 1 and the false value 0 as they are tlargeint in my tfdquery. I did not use the selected checkbox feature built into the grid.
Please sign in to leave a comment.