Greetings,
How do I change CRDBGrid color during runtime ?
For example:
CRDBGrid.Columns[0] pointed to "Amount"
IF "Amount" more than 1000 then
whole row of record change to RED
ELSE
whole row of record change to BLUE
Thanks in advance.
Change CRDBGrid color during runtime
Sample code please
Thanks.
Could you please show me some SAMPLE CODE as I could not the relevant help topic regarding CRGrid.OnGetCellParams vent handler.
Thanks again:-)
Could you please show me some SAMPLE CODE as I could not the relevant help topic regarding CRGrid.OnGetCellParams vent handler.
Thanks again:-)
that is not working for me
this is my code:
procedure TFcartas.GridGetCellParams(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; State: TGridDrawState;
StateEx: TGridDrawStateEx);
begin
if (gdFocused in State) then
begin
Background := clNavy;
AFont.Color := clWhite;
Afont.Style := [fsBold];
end;
end;
the background for the selected cell is always cl_window, on my case (white), so when i move the cursor over the cells, the text dissapears because it turns white as the background
procedure TFcartas.GridGetCellParams(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; State: TGridDrawState;
StateEx: TGridDrawStateEx);
begin
if (gdFocused in State) then
begin
Background := clNavy;
AFont.Color := clWhite;
Afont.Style := [fsBold];
end;
end;
the background for the selected cell is always cl_window, on my case (white), so when i move the cursor over the cells, the text dissapears because it turns white as the background
Try to set OnDrawDataCell event handler:
Code: Select all
procedure TFcartas.GridDrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState);
begin
if gdFocused in State then begin
OLEDBGrid.Canvas.Brush.Color := clRed;
OLEDBGrid.Canvas.Font.Color := clWhite;
OLEDBGrid.Canvas.font.Style := [fsBold];
end;
OLEDBGrid.DefaultDrawDataCell(Rect, Field, State);
end;