Delphi
--
Questions
--
Followers
Top Experts
attached are some gif files to show Master and Master2 the resizing works
Master1 and master show the problem with the TDBGrid the grid headings and columns dont resize any suggestions
Master.gif
Master1.gif
Master2.gif
Master3.gif
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Use the ColWidth property to set the width of each individual columns
This algo is crude by the resize of each column proportionally, but that's the idea, you can do whatever you want from that, like have some columns with a fixed size...
procedure TForm1.FormResize(Sender: TObject);
Var
i,TotCol:Integer;
begin
TotCol:=0;
for i:=0 to ColCount-1 do TotCol:=TotCol+sg1.ColWidths[i];
for i:=0 to ColCount-1 do sg1.ColWidths[i]:=Trunc(sg1.ColWidths[i]/TotCol*sg1.Width);
end;
procedure TForm1.AdjustColumnWidths(
var
 TotalColumnWidth, ColumnCount, GridClientWidth, Filler, i: Integer;
begin
 ColumnCount := DBGrid.Columns.Count;
 if ColumnCount = 0 then
  Exit;
 TotalColumnWidth := 0;
 for i := 0 to ColumnCount - 1 do
  TotalColumnWidth := TotalColumnWidth + DBGrid.Columns[i].Width;
 if dgColLines in DBGrid.Options then
  TotalColumnWidth := TotalColumnWidth + ColumnCount;
 GridClientWidth := DBGrid.Width - GetSystemMetrics(SM_CXVSCR
 if dgIndicator in DBGrid.Options then
 begin
  GridClientWidth := GridClientWidth - IndicatorWidth;
  if dgColLines in DBGrid.Options then
   Dec(GridClientWidth);
 end;
 if DBGrid.BorderStyle = bsSingle then
 begin
  if DBGrid.Ctl3D then
   GridClientWidth := GridClientWidth - 4
  else
   GridClientWidth := GridClientWidth - 2;
 end;
 if TotalColumnWidth < GridClientWidth then
 begin
  Filler := (GridClientWidth - TotalColumnWidth) div ColumnCount;
  for i := 0 to ColumnCount - 1 do
   DBGrid.Columns[i].Width := DBGrid.Columns[i].Width + Filler;
 end
 else if TotalColumnWidth > GridClientWidth then
 begin
  Filler := (TotalColumnWidth - GridClientWidth) div ColumnCount;
  if (TotalColumnWidth - GridClientWidth) mod ColumnCount <> 0 then
   Inc(Filler);
  for i := 0 to ColumnCount - 1 do
   DBGrid.Columns[i].Width := DBGrid.Columns[i].Width - Filler;
 end;
end;






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
procedure TForm1.FormResize(Sender: TObject);
begin
 AdjustColumnWidths(DBGrid1
end;

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ive tried setting the bottom top to false and any other combination
Delphi
--
Questions
--
Followers
Top Experts
Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Developmentâ„¢. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.