Używam kontrolki Grid FireMonkey, ale mam problem z próbą wyrównania kolumny. Od innych użytkowników postów, udało mi się stworzyć nowy typ TColumn, zastosować do tego styl (tekst jako HorzAlign = taTrailing) i teoretycznie - myślałem, że to będzie rozwiązanie. Wartości są dostarczane przez funkcję OnGetValue do kontrolki Grid.Sterowanie siatką Firemonkey - wyrównanie kolumny w prawo
Problem polega jednak na tym, że chociaż początkowo wygląda to dobrze, jeśli przewijasz pasek/kółko myszy itp. Nowa kolumna typu kolumny nie wygląda na prawidłowo odświeżającą, używając poniższej metody/kodu. Może to być błąd/funkcja siatki (lub sposób, w jaki to robię). Próbowałem .ReAlign etc ...; ale bez skutku. Jedynym sposobem na przywrócenie siatki jest zmiana rozmiaru kolumny na przykład - która następnie jest poprawnie przerysowana?
Poniższy kod pokazuje, że jest to prosty TGrid, z 2 colami, 1 standardową kolumną StringColumn i 1 moją nową wartością StringColNum (zastosowane prawe wyrównanie wuth). - Każda pomoc doceniona, ponieważ jest to podstawowy wymóg jakiejkolwiek pracy w sieci.
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.
Z pozdrowieniami. Ian.
Dzięki Mike - The "doskonała odpowiedź" Szukałem; prawdziwa supergwiazda ..! – Ian