Insert on top Row of a large TStringGrid

I am afraid that this might be the question of a β€œlong question,” but wondered if anyone had solid numbers or advice.

I have a TStringGrid that can have 3600 rows, and maybe more, we are not sure yet. Since the monitor obviously has no place for this, only 20 or 30 lines are displayed on the screen. Unfortunately, these are the first entries, and the user has to scroll down to see the lines as they are added.

It may be more convenient to reorder the lines, m with the newest and oldest last. For this, I will need to do something like this (the code may not be accurate)

// 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; 

I'm concerned about performance. If no one has experience, I will encode the test and report back.

Just wondering if anyone has any experience or opinion on this ...

+4
source share
2 answers

Try this one

 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; 
+3
source

I would recommend virtual grid control instead of VirtualTreeView. I have one written by Roman Mochalov (Roman Mochalov), which, in my opinion, is 100% open source, but not available on the Internet. I have a link here [on skydrive]:

+1
source

Source: https://habr.com/ru/post/1334171/


All Articles