delphi – 在大型TStringGrid的顶行插入
发布时间:2020-12-15 09:16:23 所属栏目:大数据 来源:网络整理
导读:我担心这可能是“一段字符串有多长”的问题,但想知道是否有人有一些硬数据或建议. 我有一个TStringGrid可能有3,600行,也许更多,我们还不确定.由于显示器显然没有空间,屏幕上只显示20或30行.不幸的是,这些是第一个写的,用户必须向下滚动才能看到添加的行. 反
我担心这可能是“一段字符串有多长”的问题,但想知道是否有人有一些硬数据或建议.
我有一个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; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |