procedure BestFitRow(const Index: Integer)
Description
The method automatically adjusts the height of the row, depending on the contents of the cells in this row.
As a rule, this method must be called in the event of the OnChange component.
Also, you must assign the WrapKind := wkWordWrap property to columns to allow wrap text in cells.
Example
// automatically adjust the height of all rows in the component
procedure Form1_TableGrid1_OnChange (Sender: string);
var
i, c: integer;
begin
c := Form1.TableGrid1.Columns.Count - 1;
for i := 0 to c do
begin
Form1.TableGrid1.Columns[i].VerticalAlignment := taAlignTop; // set the vertical alignment in the cells of the column
Form1.TableGrid1.Columns[i].WrapKind := wkWordWrap; // enable the possibility of wrapping the strings in the cells of the column
end;
c := Form1.TableGrid1.RowCount - 1;
for i := 0 to c do Form1.TableGrid1.BestFitRow(i); // for each row we call the method for auto height adjustment
end;
// also updates the height of the rows when you resize the columns
procedure Form1_TableGrid1_OnColumnResize (Sender: TObject; ACol: Integer);
var
i, c: integer;
begin
c := Form1.TableGrid1.RowCount - 1;
for i := 0 to c do Form1.TableGrid1.BestFitRow(i); // for each row we call the method for auto height adjustment
end;