I worked through the example posted here as my starting point: Change background of TTextCell in a Firemonkey TGrid
I have created a textcellstyle which references an image, and this is working well. When I run the program all the cells display the background image as expected.
From the above link, Mike Sutton (I hope you're reading this, what would we do without your input!) writes (repeated here just to make it easier):
"You can then set each of your cells StyleLookup properties to use it, or set the styles StyleName to TextCellStyle to have it picked up automatically for every TTextCell."
Following on from the query about changing the font colours (Delphi XE4 Firemonkey Grid Control - Styling cells individually), can one set the background colours dynamically as well?
My code on creating the cells:
Constructor TFinancialCell.Create(AOwner:TComponent);
begin
inherited;
StyleLookup:='textcellstyle';
StyledSettings:=StyledSettings-[TStyledSetting.ssStyle,TStyledSetting.ssFontColor];
TextAlign:=TTextAlign.taTrailing;
end;
This applies my image successfully to TFinancialCell.
But, as per the font colour query, I would like the image background to display only when a certain value is reached or whatever:
Procedure TFinancialCell.ApplyStyling;
begin
Font.Style:=[TFontStyle.fsItalic];
If IsNegative then
FontColor:=claRed
else
FontColor:=claGreen;
If IsImportant then Font.Style:=[TFontStyle.fsItalic,TFontStyle.fsBold];
If Assigned(Font.OnChanged) then
Font.OnChanged(Font);
Repaint;
end;
Any help as to how to do this would be appreciated.
FindStyleResource('background')
which should return a TRectangle and you can change it's Fill.Color. If that fails I'll take a look when I get time. – Mike Sutton