Estoy usando el control FireMonkey Grid pero tengo un problema continuo al intentar alinear correctamente una columna. De las publicaciones de otros usuarios, he logrado crear un nuevo tipo TColumn, aplicar un estilo a esto (texto como HorzAlign = taTrailing) y, en teoría, pensé que esta sería la solución. Los valores son proporcionados por la función OnGetValue al control Grid.Firemonkey Grid Control - Alineación de una columna a la derecha
El problema es, sin embargo, que aunque al principio se ve bien, si desplaza la barra/mouse, etc., la nueva columna de tipo TColumn no parece actualizarse correctamente utilizando el método/código siguiente. Podría ser un error/característica de la Grilla (o la forma en que lo estoy haciendo). He intentado .ReAlign, etc ...; pero fue en vano. La única forma de volver a poner a la red en línea es hacer un cambio de tamaño de columna, por ejemplo, que luego se redibuja correctamente?
El siguiente código muestra que es un TGrid simple, con 2 cols, 1 StringColumn estándar y 1 mi nuevo StringColNum (alineación correcta de wuth). - Cualquier ayuda apreciada ya que este es un requisito básico de cualquier trabajo de cuadrícula.
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.
Saludos cordiales. Ian.
Gracias Mike - La "respuesta perfecta" que estaba buscando; una verdadera superestrella ..! – Ian