Главная страница | назад





Article #17068: Resizing StringGrid Columns

 Question and Answer Database
FAQ2068D.txt Resizing StringGrid Columns
Category :VCL
Platform :All
Product :All 32 bit
Question:
Is it possible to automatically size a column in a TStringGrid
component to fit the text of the largest string in the column?
Answer:
The following example demonstrates auto sizing a column in a
TStringGrid Component.
Example:
procedure AutoSizeGridColumn(Grid : TStringGrid;
column : integer);
var
i : integer;
temp : integer;
max : integer;
begin
max := 0;
for i := 0 to (Grid.RowCount — 1) do begin
temp := Grid.Canvas.TextWidth(grid.cells[column, i]);
if temp> max then max := temp;
end;
Grid.ColWidths[column] := Max + Grid.GridLineWidth + 3;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AutoSizeGridColumn(StringGrid1, 1);
end;
7/16/98 4:31:28 PM

Last Modified: 01-SEP-99