0
我正在使用Delphi XE5,并试图根据每个单元格的内容格式化TGrid。对于数字,我希望它们在单元格中右对齐,并用红色字体显示底片。所有其他数据应该在单元格中左对齐。当我向上或向下滚动网格颜色/对齐出错时,下面的代码实现了这一点。Firemonkey XE5 TGrid使用格式化单元格滚动问题
type
TMyColumn = class(TStringColumn)
end;
procedure TForm1.Grid1GetValue(Sender: TObject; const Col, Row: Integer;
var Value: TValue);
var
vMyCell : TStyledControl;
i : Integer;
s : String;
begin
s := gHoldingGrid.Cells[ Col, Row ];
vMyCell := TMyColumn(Grid1.Columns[ Col ]).CellControlByRow(Row);
if ((vMyCell <> nil) AND (vMyCell is TTextCell))
then begin
TTextCell(vMyCell).StyledSettings := [];
if TryStrToInt(s, i)
then begin
if StrToInt(s) < 0
then TTextCell(vMyCell).FontColor := claRed
else TTextCell(vMyCell).FontColor := claBlue;
TTextCell(vMyCell).TextAlign := TTextAlign.taTrailing;
end { if TryStrToInt(s, i) }
else begin
TTextCell(vMyCell).TextAlign := TTextAlign.taLeading;
TTextCell(vMyCell).FontColor := claGreen;
end; { else .... if TryStrToInt(s, i) }
vMyCell.ApplyStyleLookup;
end; { if ((vMyCell <> nil) AND (vMyCell is TTextCell)) }
Value := s;
end;
有人可以帮我解决这个问题吗?我已经在这个论坛上尝试了很多例子,但是无法让它们工作,并且很好,而且确实卡住了。
非常感谢预期。
谢谢迈克。我认为我至少在这个代码的正确方向,但它似乎不是! –