How to get StringGrid columns to match grid width?

I have been looking for a solution without luck for a long time. Does anyone know an easy way to do this? I would like to stretch, for example, the second ear of my grid so that it matches the width of the grid!

+4
source share
2 answers

Use the ColWidths property, for example:

 with StringGrid1 do ColWidths[1] := ClientWidth - ColWidths[0] - 2 * GridLineWidth; 

And for a more reliable and flexible solution, consider all fixed columns and parameterize the column index:

 procedure SetColumnFullWidth(Grid: TStringGrid; ACol: Integer); var I: Integer; FixedWidth: Integer; begin with Grid do if ACol >= FixedCols then begin FixedWidth := 0; for I := 0 to FixedCols - 1 do Inc(FixedWidth, ColWidths[I] + GridLineWidth); ColWidths[ACol] := ClientWidth - FixedWidth - GridLineWidth; end; end; procedure TForm1.Button1Click(Sender: TObject); begin SetColumnFullWidth(StringGrid1, 4); end; 
+7
source

Solution If there is more doubt the command " grid.AutoFitColumns () " Where the grid is one "TAdvStringGrid";

;)

-1
source

All Articles