It may be basic but I'm have a ** of a time finding sample code to change a row color of a stringgrid based on a value from a database in Firemonkey. I have data coming from a MDB no problems but need the row to be certain colors for ie '1' = red '2' = green etc. I know I have to access the Style elements somehow 'OnApplyStyleLookup'? but at what stage. I have seen questions on changing text style and colour etc but I am digging a hole for myself trying to get to the 'background' element and applying. Any help would be greatly appreciated. Cheers Richard ...(newbie to Firemonkey)
{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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With