var
i, WidthOfCols: integer;
begin
WidthOfCols := 0;
for i := 1 to DrawGrid1.ColCount - 1 do
WidthOfCols := DrawGrid1.ColWidths[i];
DrawGrid1.ColWidths[0] := form1.width - WidthOfCols;
end;
What do I do?
A: You have it close, but no cigar.
var
i, WidthOfCols: integer;
begin
WidthOfCols := 0;
for i := 1 to DrawGrid1.ColCount - 1 do
WidthOfCols := DrawGrid1.ColWidths[i];
DrawGrid1.ColWidths[0] :=
form1.ClientWidth - WidthOfCols - (DrawGrid1.ColCount
+ 1);
end;
What this is doing is different from what you were doing on a few points.
1. The form's client area must be used instead of the form's width.
This is because we don't want the frame size figured into the value.
2. We need to subtract the lines of the grid itself. The
width of a column excludes the lines that define it. We use the ColCount
+ 1 because there are lines on both the left and right sides of it.
Note: run this procedure on the form.create and the form.resize to keep
everything looking good.