How do I make a StringGrid's columns fit the grid's width?
Use the ColWidths
property, like so:
with StringGrid1 do
ColWidths[1] := ClientWidth - ColWidths[0] - 2 * GridLineWidth;
And for a more robust and flexible solution, take all fixed columns into account 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;