Advertisement
jpfassis

AutoSizeDBGrid - collumns - Delphi

May 26th, 2020
1,041
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.89 KB | None | 0 0
  1. procedure TForm1.AutoSizeDBGrid(const xDBGrid: TDBGrid);
  2. var
  3.   I, TotalWidht, VarWidth, QtdTotalColuna : Integer;
  4.   xColumn : TColumn;
  5. begin
  6.  
  7. TotalWidht :=0;
  8. VarWidth :=0;
  9. QtdTotalColuna := 0;
  10.  
  11.   for I:=0 to -1 + xDBGrid.Columns.Count do
  12.   begin
  13.     TotalWidht := TotalWidht + xDbGrid.Columns[I].Width;
  14.     Inc(QtdTotalColuna);
  15.   end;
  16.  
  17.   if QtdTotalColuna = 0 then
  18.    Exit;
  19.  
  20.    if not (TotalWidht < xDBGrid.ClientWidth) then
  21.     Exit;
  22.  
  23.   if dgColLines in xDBGrid.Options then
  24.     TotalWidht := TotalWidht + xDBGrid.Columns.Count;
  25.  
  26.   if dgIndicator in xDBGrid.Options then
  27.     TotalWidht := TotalWidht + IndicatorWidth;
  28.  
  29.   VarWidth := xDBGrid.ClientWidth - TotalWidht;
  30.  
  31.   if QtdTotalColuna > 0 then
  32.     VarWidth := VarWidth div QtdTotalColuna;
  33.  
  34.   for I:=0 to -1 + xDBGrid.Columns.Count do
  35.   begin
  36.     xDBGrid.Columns[I].Width:=xDBGrid.Columns[I].Width+VarWidth;
  37.   end;
  38.  
  39. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement