Page 1 of 1
Change CRDBGrid color during runtime
Posted: Tue 03 Jan 2006 06:15
by ascll
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.
Posted: Tue 03 Jan 2006 10:03
by Ikar
Use CRGrid.OnGetCellParams vent handler.
Sample code please
Posted: Wed 04 Jan 2006 03:18
by ascll
Thanks.
Could you please show me some SAMPLE CODE as I could not the relevant help topic regarding CRGrid.OnGetCellParams vent handler.
Thanks again:-)
Posted: Wed 04 Jan 2006 14:44
by Ikar
Use something like this
procedure TForm1.CRGrid1GetCellParams(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; State: TGridDrawState;
StateEx: TGridDrawStateEx);
begin
background := clRed;
end;
that is not working for me
Posted: Fri 10 Aug 2007 01:03
by Willo
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
Posted: Fri 10 Aug 2007 12:24
by Ikar
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;