Disable TStringGrid from redraw until ready lazarus / 31-LCL ---------------------------------------------------------------------- gompertz · 2022-10-24 02:16 Hi, I have a rather large dataset that I'm displaying in TStringGrid (read from a tab-delim file), and I am updating it by walking the rows/columns in a nested loop and populating the cells with the typical Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i StringGrid1.Cells[j, i] := 'foo'; It's just a smidge slow however.  My procedure runs instant with that line commented out, so I'm believing it's because on every Cells write the framework is trying to redraw the component. I've tried making visibility false, and then true afterwards but this doesn't seem to help.  I did put StringGrid1.BeginUpdate and StringGrid1.EndUpdate before/after the meaty part, which did help a lot, but I'm still just a little slower than I'd like. Am I correct in assuming a repaint is taking place everytime I set Cells, even with visibility set to false?  Is there a way to disable any painting before I load all the cells, and call for a repaint after? Thanks! ---------------------------------------------------------------------- dbannon · 2022-10-24 05:43 Maybe, just maybe, you need to consider using TListView in its OwnerData mode. It does what you are looking for as stated here but maybe on the other things you need ? Hmm, maybe TStringGrid has an OwnerData model ?  I don't use it. Davo ---------------------------------------------------------------------- wp · 2022-10-24 12:37 Quote from: gompertz on October 24, 2022, 04:16:11 amI have a rather large dataset that I'm displaying in TStringGrid (read from a tab- delim file), and I am updating it by walking the rows/columns in a nested loop and populating the cells with the typical Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i StringGrid1.Cells[j, i] := 'foo';How many rows and columns are you talking of? ---------------------------------------------------------------------- jcmontherock · 2022-10-24 14:12 Maybe, you can execute:  StringGrid1.BeginUpdate without executing StringGrid1.EndUpdate before you're ready to update it. Update, in any casa will be done on the only visible part of StringGrid. ---------------------------------------------------------------------- gompertz · 2022-10-24 14:33 HI thanks for the replies all.  Quote from: wp on October 24, 2022, 02:37:06 pmHow many rows and columns are you talking of? The data is about 15,000 rows and 50 columns. Quote from: jcmontherock on October 24, 2022, 04:12:45 pmMaybe, you can execute:  StringGrid1.BeginUpdate without executing StringGrid1.EndUpdate before you're ready to update it. Update, in any casa will be done on the only visible part of StringGrid. Sorry I wasn't clear, I do the BeginUpdate before the start of populating the cells, and when 100% done call EndUpdate. ---------------------------------------------------------------------- gompertz · 2022-10-24 14:46 I just looked at the source in grids.pas... when you write to the Cells property, the setter is SetCells. Looking at the source, it looks that every changed cell calls UpdateCell which invalidates the cell, and (to my understanding) causes a repaint.  It doesn't check if the object is visible, or if the cells are in view.  Unless I'm misunderstanding??? (entirely possible, only been doing FPC/Laz for a week).  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TCustomStringGrid.SetCells(ACol, ARow: Integer; const AValue: string);  procedure UpdateCell;  begin    if EditorMode and (aCol=FCol)and(aRow=FRow) and      not (gfEditorUpdateLock in GridFlags) then    begin      EditorDoSetValue;    end;    InvalidateCell(aCol, aRow);  end;var  C: PCellProps;begin  C:= FGrid.Celda[aCol,aRow];  if C<>nil then begin    if C^.Text<>nil then      StrDispose(C^.Text);    C^.Text:=StrNew(pchar(aValue));    UpdateCell;    FModified := True;  end else begin    if AValue<>'' then begin      New(C);      C^.Text:=StrNew(pchar(Avalue));      C^.Attr:=nil;      C^.Data:=nil;      FGrid.Celda[aCol,aRow]:=C;      UpdateCell;      FModified := True;    end;  end;end; ---------------------------------------------------------------------- wp · 2022-10-24 16:04 Quote from: gompertz on October 24, 2022, 04:33:18 pmThe data is about 15,000 rows and 50 columns. Can't it be that the speed issue you are seeing is due to reading of the csv file rather than populating the grid? The attached demo fills 50 cols x 15000 rows with a constant string, and this takes about 100 ms on my system. Running with or without Begin/EndUpdates, surprisingly, does not make much of a difference. ---------------------------------------------------------------------- winni · 2022-10-24 17:11 Hi! I work with a stringGrid with 70.000 rows and 19 cols. Loadig the CSV- File takes less than 1.5 seconds. What really takes time in the StringGrid is allocating new rows if you do it one by one. That is bothering slow.   Allocate all your needed rows at the beginning at once. Winni ---------------------------------------------------------------------- gompertz · 2022-10-24 18:24 Thanks everyone for the help.  On Discord we were able to narrow down that it was by me calling a custom procedure to resize all the column widths based on the cell content.  However this procedure was very slow as it called TextWidth on every cell which is costly.  Unfortunately, I went down the wrong path thinking it was the Cells setter that was the issue (by commenting it out and seeing the speed increase) - but this was only because the custom column-widths procedure then blasted through the cells as there was nothing to measure. *facepalm*. ---------------------------------------------------------------------- jamie · 2022-10-24 23:08 Guess you would be better off drawing the cells yourself using owner draw for example, this way you can calculate only what is going to be on the screen.  that would take care of the width in any case. Not sure about if you try this with the height however.