I am trying to create a query that will be able to load into a tcxtreelist in delphi
I have a structure like this
-Season
Month
- week
All I have is the structure. I still need to know how to constructed my query, so I can load this onto my treelist
if anyone knows how to do this, that really appreciate your help
I'm not sure the cxDBTreeList, which was my first thought, is really suited to your purpose because it only works for a self-referencing dataset (See the Devex online help for what this means). On the other hand, it is quite straightforward, if a little long-winded to set up a cxTreeList to display your data.
In the following example, for simplicity I've left out the "week" level of your structure and replaced the "Season" level by a "Quarter" (three-month period) one.
To try the example below:
Create a new project, and on its form, drop a TClientDataSet named CDS1 and a TcxTreelist.
Also, drop a TDataSource and TDBGrid onto the form and connect them up to the CDS in the usual way so that you can see the data you're working with.
Edit the code of the main form as shown below. It's probably easiest if you create a new
OnCalcFields
event forCDS1
ond then cut'n paste the calcfields code into it.As you'll see from the code, the calculated fields are actually of type
fkInternalCalc
. The reason for this is so that the CDS can be indexed on them (unlikefxCalculated
fields which don't permit this).The project is intended to be as self-contained as possible: that's why the CDS's fields and the cxTreeList columns are all created in code, and why the project uses a CDS as the dataset, so that all the data can be created in code and doesn't require an external database or server.
You'll see that once the
Quarter
andMonth
nodes are set up, it's pretty trivial to "hang" the individual data rows off them (in thewhile not CDS1.eof
loop).The
Description
calculated column is there so as to be able to display some information specific to an individual data row in the cxTreeList. Obviously, you could have columns which get their values from individual dataset fields instead if you wanted.Code: