0
votes

I'm using Delphi XE7 for developing Android application. In that I have used TStringGrid component and then I have used StringGrid.cells[0, 0] := 'Test' And how can I change the Font colour of that particular cell which I have shown in the code. And also I have this sample code, but I can not change the font colour of the particular cell. Please anybody explain me how to change the font colour of the particular cell value. And I'm using Delphi XE7 and I'm targeting Android mobile.

Thanks..

3
What do you know about FMX styling? I suspect that you are not familiar with that. Until you become familiar with it you are likely to ask this question about every single control you ever use. It started with TToolbar, now TStringGrid.David Heffernan
You asked about TToolbar here and gradient buttons here, and now a stringgrid cell. Please do some research on working with FMX styles, so you're not asking how to do every little thing affecting appearance with every single control.Ken White

3 Answers

1
votes

In a FireMonkey TStringGrid there are no per cell styling options. You will either need to use a third party grid control or roll something yourself from TGrid.

You can find plenty of material on the latter on my site at http://monkeystyler.com/guide

0
votes

At last, I have found the solution which I required. Please follow the Steps. We can able to change the font color in TStringGrid itself, No need to use TGrid. Please follow the below steps.

First assign this in FormCreate event:

  StringGrid1.DefaultDrawing := False;

then write this in StringGrid DrawColumnCell event:

  Canvas.fill.Color := TAlphaColorRec.Green;
  Canvas.FillText(Bounds, (Value.AsString),
    false, 100, [], TTextAlign.taLeading, TTextAlign.taCenter);
0
votes

Works in XE8 as well for the TStringGrid OnDrawColumnCell event.

Herewith an example that keeps the color on black but sets the font styling to bold. Tip, add 2 pixels padding for the font, from the left margin.

var Rect : TRectF;
begin
  Rect := Bounds;
  Rect.Left := Rect.Left + 2;
  Canvas.Font.Style := [TFontStyle.fsBold];
  Canvas.Fill.Color := TAlphaColorRec.Black;
  Canvas.FillText(Rect, (Value.AsString), false, 100, [], TTextAlign.taLeading, TTextAlign.taCenter);
end;

What I missed in the beginning was not setting the DefaultDrawing to false! After I set that, the event was accepting changes to the Canvas.