我担心这可能是“一段字符串有多长”的问题,但想知道是否有人有一些硬数据或建议. 我有一个TStringGrid可能有3,600行,也许更多,我们还不确定.由于显示器显然没有空间,屏幕上只显示2
我有一个TStringGrid可能有3,600行,也许更多,我们还不确定.由于显示器显然没有空间,屏幕上只显示20或30行.不幸的是,这些是第一个写的,用户必须向下滚动才能看到添加的行.
反转行的顺序可能更加用户友好,m是最新的最后一个.要做到这一点,我需要做这样的事情(代码可能不完全)
// slightly quicker if there are many rows & no flicker
myStringGrid.Visible := False;
rowCount := myStringGrid.RowCount;
for row := 1 to Pred(rowCount) do
myStringGrid.Rows[row + 1] := myStringGrid.Rows[row];
myStringGrid.RowCount := myStringGrid.RowCount + 1;
// now add new row...
myStringGrid.Cells[1, 0] := <somthing>;
myStringGrid.Cells[1, 1] := <somthing else>;
myStringGrid.Cells[1, 2] := <etc>;
TestRunDataStringGrid.Visible := True;
我担心表现.如果没有人有任何经验,我会编写测试代码.报告回来.
只是想知道是否有人有这方面的经验或意见……
试试这个吧type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
---
---
private
{ Private declarations }
public
{ Public declarations }
end;
type
TStringGridHack = class(TStringGrid)
protected
procedure InsertRow(ARow: Longint);
end;
implementation
{$R *.dfm}
procedure TStringGridHack.InsertRow(ARow: Longint);
var
iRow: Integer;
begin
iRow := Row;
while ARow < FixedRows do Inc(ARow);
RowCount := RowCount + 1;
MoveRow(RowCount - 1, ARow);
Row := iRow;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TStringGridHack(StringGrid1).InsertRow(1);
end;
