ASG: Automatic row height according text in cell


Delphi XE3 Pro
is it possible that the row heights adjust themselfs according text that is inside theire cells?
E.g. I'll have AdvRichEditor as cell editor and when I write text in the cell that exceeds the cells width, a word wrap is done, which is good, but I don't see the second line anymore. It would be nice if AdvStringGrid could do this row height adjustment itself.
Also when I change the font size, a row height adjustment would be nice.
The row height of course, would need to be according the cell of the row that needs the most height.

Please let me know if this is already possible and if not, if you consider implementing that.


You can use grid.AutoSizeRow(s) to have the grid automatically adapt the row height to the height of text in cells.

this doesn't do anything when I try this.

Does it depend on other options? (I tried with and without Options.GoRowSizing)

Calling grid.AutoSizeRows() does not depend on other settings.

This code snippet applied to a default TAdvStringGrid shows how this auto sizing works:

procedure TForm3.FormCreate(Sender: TObject);
  advstringgrid1.Cells[1,1] := 'line1'#13#10'line2'#13#10'line3';

I did use it wrong, works fine now


In a TDBAdvGrid, I want to auto resize the rows if there is any change to the width of a column, either by resizing the column directly or if I resize the form and a column is set to stretch (my column 4 is set to stretch), and I want it done efficiently.

I put a call to AutoSizeRows after the grid is loaded and on the grid's OnColumnSizing event. However, the OnColumnSizing event only occurs if I manually resize the column and does not occur when the form is resized (my stretch column get resized, so why not? Different event?). So, I added the call to the grid's OnResize event, but that also does not get invoked when resizing the form. Note: the grid is not aligned (alNone) but is anchored top, left, bottom, right. So I would expect that event to occur when resizing the form, but doesn't (why not?). So I put the call into its parent panel's OnResize event which basically does the same thing..

Is this the most efficient way to do all of this? Seems like if I change the form's height it still calls AutoSizeRows needlessly. It would be better if auto stretching a column calls the OnColumnSizing event, but as I mentioned, it doesn't.

Delphi 10.4.2

OnColumnSize() was not triggered during a stretch invoked resize.
It is a good suggestion to also trigger it in this case. We did this improvement that will be included in the next update.