I am using the FireMonkey grid control, but I have a problem trying to align the column. From the messages of other users, I managed to create a new type of TColumn, apply a style to it (text HorzAlign = taTrailing), and in theory I thought that it would be a solution. Values ββare provided by the OnGetValue function for managing the grid.
The problem is that although at first it looks fine if you scroll the mouse wheel / mouse wheel, etc., a new column of type TColumn does not display correctly using the method / code below. This may be a bug / feature of the Grid (or the way I do it). I tried .ReAlign etc .; but to no avail. The only way to get the grid back to the row - for example, resize a column - which then redraws correctly?
The code below shows that it is a simple TGrid, with 2 columns, 1 standard StringColumn and 1 my new StringColNum (using the correct wuth alignment). - Any help is appreciated as this is a basic requirement for any grid work.
unit Unit1; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.Objects, FMX.Grid, FMX.Layouts, FMX.Edit; type TForm1 = class(TForm) Grid1: TGrid; Button1: TButton; StyleBook1: TStyleBook; procedure Grid1GetValue(Sender: TObject; const Col, Row: Integer; var Value: Variant); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; TStringColNum = class(TStringColumn) private function CreateCellControl: TStyledControl; override; public constructor Create(AOwner: TComponent); override; published end; var Form1: TForm1; implementation {$R *.fmx} constructor TStringColNum.Create(AOwner: TComponent); begin inherited; end; function TStringColNum.CreateCellControl: TStyledControl; var t:TEdit; begin Result:=TStringColNum.Create(Self); Result.StyleLookup := 'textrightalign'; end; procedure TForm1.Button1Click(Sender: TObject); begin Grid1.AddObject(TStringColumn.Create(Self)); Grid1.AddObject(TStringColNum.Create(Self)); // Right Aligned column? Grid1.RowCount:=5000; Grid1.ShowScrollBars:=True; end; procedure TForm1.Grid1GetValue(Sender: TObject; const Col, Row: Integer; var Value: Variant); var cell: TStyledControl; t: TText; begin if Col=0 then Value:='Row '+IntToStr(Row);; if Col=1 then begin cell := Grid1.Columns[Col].CellControlByRow(Row); if Assigned(cell) then begin t := (Cell.FindStyleResource('text') as TText); if Assigned(t) then t.Text:='Row '+IntToStr(Row); end; end; end; end.
Sincerely. Yang.
Ian
source share