1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Adjust size of the columns of a DBGRID

Discussion in 'Delphi Programming' started by medreis, Nov 6, 2015.

  1. medreis
    Offline

    medreis DF Junior

    procedure DBGridAjustaColunas( const Grid: TDBGrid );
    var a : array of integer;
        i,
        n : integer;
        DataSet: TDataSet;
    begin
      SetLength( a, Grid.Columns.Count);
      for i:= 0 to Grid.Columns.Count - 1 do
          a := Grid.Canvas.TextWidth(Grid.Columns.Title.Caption);

      DataSet:= Grid.DataSource.DataSet;
      DataSet.DisableControls;

      try
        while not DataSet.Eof do begin
              for i:= 0 to Grid.Columns.Count -1 do begin
                  n:= Grid.Canvas.TextWidth( DataSet.Fields.Text );
                  if n>a then a:=n;
              end;
              DataSet.Next;
        end;

        for i:= 0 to Grid.Columns.Count -1 do begin
            Grid.Columns.Width := a + 5;

            {checka espaço para colocar a imagem de ordenação na coluna}
            if Grid.Columns.Items.Width <
               Grid.Canvas.TextWidth(Grid.Columns.Title.Caption)+5 then
               Grid.Columns.Width := Grid.Columns.Width + 5;
        end;

        if not DataSet.IsEmpty then DataSet.First;

      finally
        DataSet.EnableControls;
      end;

    end;
     
  2. ilanamlas1
    Online

    ilanamlas1 Guest

    you are best
     
  3. pcesarlopes
    Online

    pcesarlopes Guest

Share This Page