2
votes

NEED HELP..I am using delphi 10.1 berlin. There are some different with other previus version of Embarcadero Delphy Code Gear. I need to change font color in rows of TGrid. Whith this next code i will change backgrond color but i need to change only Font Color :

  aRowColor.Color := arSTATUS_GRID_COLOR[0];
  Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
  Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
1

1 Answers

4
votes

Instead of calling Column.DefaultDrawCell(), you can use FMX.Graphics.TCanvas.FillText() in the grids OnDrawColumnCell() event.

The documentation explains the details, but the main point is to set Canvas.Fill.Color to the desired color before calling Canvas.FillText()

Sample code:

procedure TForm28.Grid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
  const Column: TColumn; const Bounds: TRectF; const Row: Integer;
  const Value: TValue; const State: TGridDrawStates);
begin
  case Row of
    0: Canvas.Fill.Color := TAlphaColors.Red;
    1: Canvas.Fill.Color := TAlphaColors.Blue;
    2: Canvas.Fill.Color := TAlphaColors.Green;
    3: Canvas.Fill.Color := TAlphaColors.Blueviolet;
  end;
  Canvas.FillText(Bounds, Value.AsString, false, 1, [], TTextAlign.Leading, TTextAlign.Center);
end;

And how it looks like:

enter image description here