Change CRDBGrid color during runtime

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ascll
Posts: 4
Joined: Fri 28 Jan 2005 09:05

Change CRDBGrid color during runtime

Post by ascll » Tue 03 Jan 2006 06:15

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.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 03 Jan 2006 10:03

Use CRGrid.OnGetCellParams vent handler.

ascll
Posts: 4
Joined: Fri 28 Jan 2005 09:05

Sample code please

Post by ascll » Wed 04 Jan 2006 03:18

Thanks.

Could you please show me some SAMPLE CODE as I could not the relevant help topic regarding CRGrid.OnGetCellParams vent handler.

Thanks again:-)

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Wed 04 Jan 2006 14:44

Use something like this

procedure TForm1.CRGrid1GetCellParams(Sender: TObject; Field: TField;
AFont: TFont; var Background: TColor; State: TGridDrawState;
StateEx: TGridDrawStateEx);
begin
background := clRed;
end;

Willo
Posts: 34
Joined: Thu 24 Aug 2006 18:29

that is not working for me

Post by Willo » Fri 10 Aug 2007 01:03

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

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 10 Aug 2007 12:24

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;

Post Reply