根据数据的值在firemonkey stringgrid上着色单元格背景

Ric*_*and 9 delphi firemonkey

它可能是基本的,但我有**的时间查找示例代码,以根据Firemonkey中的数据库中的值更改stringgrid的行颜色.我有来自MDB的数据没有问题,但需要行是某些颜色,即'1'=红色'2'=绿色等我知道我必须以某种方式访问​​Style元素'OnApplyStyleLookup'?但在什么阶段.我已经看到了关于改变文本样式和颜色等的问题,但我正在为自己试图找到'背景'元素和应用挖洞.任何帮助将不胜感激.干杯理查德......(Firemonkey的新手)

小智 5

{OnDrawColumnCell event}

procedure OnDrawColumnCell(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
  const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
  RowColor : TBrush;
begin

  RowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);

{you can check for values and then set the color you want}
  if Value.ToString = 'red' then
     RowColor.Color := TAlphaColors.Red;

  Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);

  { perform default drawing }
  TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
    Value, State);
end;
Run Code Online (Sandbox Code Playgroud)