I think you should be able to do this in a fairly straightfoward manner. The fact
that the cxGrid can do grouping of data rows and can be switched into and out of
grouping mode shows that once the grid has loaded the dataset, it has all the
data necessary available to group, ungroup and sort the rows in the grid without having
to re-traverse the related dataset. The data is accessible via the Values property of the DBTableView's DataController.
You can access the data rows in a DBTableView in the grid via the Values property
of its associated DataController (see other answer or the cxGrid's Online Help)
as if it were a two-dimensional array or matrix - the first dimension is the rows
of the grid and the second, the index of one of the column values of the grid.
How I would attempt your task would be to
Add an fkInternalCalc flag field to the dataset to indicate how the row should
be colored. There is on need to set its value in the OnCalcFields event, nor do
anything else in OnCalcFields. The reason for including this calculated field
is just that it's an easy way of having a Values[] value for it without getting
involved in "unbound" grid columns.
Once the data is loaded into the grid, process it as a 2D array to work out which
rows need to be specially colored and set the Values[entry] for the calculated field
Use the DBTableView's OnCustomDrawCell event to color the cells as you require.
This may require a bit of fine-tuning of its implementation details but I think that in principle it should work.
NB: This will only work if the DataController's IsGridMode property is set to False.
If it is set to True, only a sub-set of the dataset's rows are loaded at any one time,
so the grid will not group and you will not be able to process the whole of the dataset
using its 2D representation in the the DataController's Values property.