[DUG] Firemonkey grid colours

John Bird johnkbird at paradise.net.nz
Wed Oct 26 19:01:46 NZDT 2016


For a Firemonkey stringgrid I wish to color some rows depending on the data in one cell  (column 3 has a web return code from a web call, eg 200 or 404 etc)
Firemonkey is quite different from how to do it in a VCL stringgrid.   Example below is best code I have found so far.
This code works in Windows but not android  - ie in android cbxShowColor being checked shows each cell with black blackground.  If unchecked, displays on white background as it should.
Question 1 – does anyone know ideal way to show colors in a grid (either font or background would be fine).   See DrawColumnCell code below which is called when DefaultDraw is set to false.
procedure TfrmURLTest.grdURLDrawColumnCell(Sender: TObject; const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
  const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
celltxt:string;
code1:Char;
aRowColor: TBrush;
begin

//it's better to write this line into create
  code1:='1';
  celltxt:=grdURL.Cells[3,Row];
  if(length(celltxt) > 0) then code1:=celltxt[1];
  aRowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
  //-----
  if cbxShowColor.IsChecked then
  begin
  case code1 of
  '1':  aRowColor.Color := TAlphaColors.white;
  '2':  aRowColor.Color := TAlphaColors.palegreen;    //lightgreen;
  '4':  aRowColor.Color := TAlphaColors.Salmon;   //Yellow;
  '5':  aRowColor.Color := TAlphaColors.Red;
  'E':  aRowColor.Color := TAlphaColors.Red;
  end;
  end else
  begin
    aRowColor.Color := TAlphaColors.white;
  end;

  //setting DefaultDraw to true does not seem to turn this code off
  Canvas.FillRect(Bounds, 0, 0, [], 1, aRowColor);
  Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
  aRowColor.free;
end;

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://listserver.123.net.nz/pipermail/delphi/attachments/20161026/693c5181/attachment.html 


More information about the Delphi mailing list