Hi All, I have a DBGrid with 6-Columns and Widths of 30, 30, 50,130, 130, 130. When I make the Main Form wider or narrower, I want to keep the Column Widths proportional. I am at the limit of my Math skills and this is not working at all well. Can someone please tell me how to do this. There seems to be a Rounding problem as I keep getting varying white-space to the right of the last column.
Code:
procedure SetColumnWidths;
var
i : Integer;
aPcnt : Real;
aWid : Real;
anInc : Integer;
Smaller : Boolean;
begin
if aClientWidth = ClientWidth then Exit;
Smaller:=aClientWidth > ClientWidth;
aPcnt:=(((aClientWidth-ClientWidth) / ClientWidth) * 100.0);
for i:=0 to dbgridItems.Columns.Count-1 do
begin
aWid:=dbgridItems.Columns[i].Width;
anInc:=Abs(Round(aWid * aPcnt / 100.0));
if Smaller then
dbgridItems.Columns[i].Width:=dbgridItems.columns[i].Width-anInc else
dbgridItems.Columns[i].Width:=dbgridItems.columns[i].Width+anInc;
end;
aClientWidth:=ClientWidth;
aClientHeight:=ClientHeight;
end;