我正在使用FireMonkey網格控件,但在嘗試右對齊列時存在持續的問題。從其他用戶的貼子,我已經成功地創建一個新的TColumn類型,樣式應用於此(文本爲HorzAlign = taTrailing),並在理論 - 認爲這將是解決方案。這些值由OnGetValue函數提供給Grid控件。Firemonkey網格控件 - 將列對齊到右邊
然而,問題是,儘管起初它看起來不錯,如果你滾動欄/鼠標滾輪等新的TColumn類型列不會出現使用下面的方法/代碼正確刷新。它可能是網格的一個bug /功能(或者我正在做這件事的方式)。我嘗試過.ReAlign等等。但無濟於事。讓電網回線的唯一方法是做一個調整列 - 例如,然後重新繪製正確?
下面的代碼顯示它是一個簡單的TGrid,帶有2個cols,1個標準StringColumn和1個新的StringColNum(應用了wuth右對齊)。 - 任何幫助讚賞,因爲這是任何電網工作的基本要求。
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.
親切的問候。伊恩。
感謝邁克 - 「完美的答案」我一直在尋找;一個真正的超級明星..! – Ian 2012-02-12 21:15:56