Here is some working code from my program that does something like this.
procedure TDoDockets.grDocketsDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with grDockets do
begin
if (qDocketsOpenCost.asinteger > 1) and (datacol = 5)
then canvas.font.color:= clRed;
if datacol = 9 then // status
if qDocketsColour.Value <> 0
then Canvas.font.color:= tcolor (qDocketsColour.Value);
if datacol = 10 then // attention
if qDocketsAttention.asinteger = 1
then canvas.brush.color:= clRed;
if qDocketsUrgent.asinteger = 1 then canvas.brush.color:= 10092543;
// light yellow
DefaultDrawColumnCell (Rect, DataCol, Column, State);
end
end;
grDockets is the grid, and qDockets is the request displayed in the grid. Some columns can be drawn in a different color depending on the displayed value, and in one case (qDocketsUrgent = 1) the entire background color of the line changes.
source
share