1
votes

I created a Stringgrid in Delphi Firemonkey XE7 for an application and filled it with data from my MySQL database. To enlarge the font size I used this code:

procedure TFormSearchRecipient.sgRecipientDrawColumnCell(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
  const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var b : TRectF; border: integer;
begin
  //following leaves in the end a border so that the marked item can be seen
  b := bounds;
  border:= 2;
  b.Top := b.Top + border;
  b.Left := b.Left - border;
  b.Height := b.Height - 2 * border;
  b.Width := b.Width - 2 * border;

  //colors the background white so that the data cannot be seen anymore
  Canvas.Fill.Color := TAlphaColorRec.White;
  Canvas.FillRect(b, 0, 0, [], 1);
  //change the canvas text options
  Canvas.Fill.Color := TAlphaColorRec.Black;
  Canvas.Font.Size := 25;
  //write the content
  Canvas.FillText(Bounds, Value.AsString , False, 1, [] , TTextAlign.Leading);
end;

I hope some of you can understand what this code does... This picture might help.

My question is now: how can I set the header and how can I enlarge the font size of the header or - if that is not possible - how can I disabled, delete or hide the header?

Thanks in advance!

Greetings Lea

2

2 Answers

4
votes

Simple way: you can hide header by uncheck option Header in StringGrid.Options at designtime.

Or, in runtime: StringGrid.Options:=StringGrid.Options - [TGridOption.Header]

For draw header text you can use OnDrawColumnHeader event. For example:

procedure THeaderFooterForm.sg1DrawColumnHeader(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF);
begin
  Canvas.Fill.Color := TAlphaColorRec.White;
  Canvas.FillRect(Bounds, 0, 0, [], 1);
  Canvas.Font.Size := 25;
  Canvas.Fill.Color := TAlphaColorRec.Black;
  Canvas.FillText(Bounds, Column.Header , False, 1, [] , TTextAlign.Leading);
end;

Edit column header text in designtime, by right-click on StringGrid and choose "Items editor". Select any column and set Header property in Object Inspector.

Or, in runtime: sg1.Columns[zero_based_column_index].Header:='some text';

The last question - how to set header height...I dont know, how to do this in runtime. TStringGrid and TCustomGrid use private field FHeader, wich update in TCustomGrid.UpdateHeader method by copying values from Columns. No property or event or method to access FHeader outside from FMX.Grid unit... But you still can customize style. Just choose stringgridstyle.background.header in Style editor and edit Height property in Object Inspector.

1
votes

OnApplyStyleLookup:

var header:Theader;
begin
header:=THeader(TStringGrid(Sender).findStyleResource('Header'));
if Assigned(header) then
   header.height:=100;
end;