AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

"Optimale Breite" bei StringGrid einstellbar?

Ein Thema von daywalker-dj-k · begonnen am 5. Mär 2004 · letzter Beitrag vom 9. Aug 2019
Antwort Antwort
Seite 2 von 2     12   
peterbelow

Registriert seit: 12. Jan 2019
Ort: Hessen
672 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: "Optimale Breite" bei StringGrid einstellbar?

  Alt 9. Aug 2019, 13:32
hallo,
kann man irgendwo einstellen, dass das stringgrid die optimale breite nutzen soll (also quasi wie z.b. bei excel). die breite soll sich automatisch so einstellen, das der länste text so gerade darstellbar ist.

oder muss man das von hand programmieren?

danke
mfg
tkliewe
Delphi-Quellcode:
{!
<summary>
SetGridColumnWidths sizes the columns of a grid to fit their content.</summary>
<param name="Grid">
is the grid to modify. This parameter cannot be nil.</param>
<param name="Columns">
specifies the columns to resize. If an empty array is passed for Columns
all columns are sized, otherwise only those whos index is in Columns
are sized. </param>
}

procedure SetGridColumnWidths(Grid: TStringGrid;
  const Columns: array of Integer);

procedure SetGridColumnWidths(Grid: TStringGrid;
  const Columns: array of Integer);

  function ColInArray(n: Integer): Boolean;
  var
    i: Integer;
  begin
    if Length(Columns) = 0 then
      Result := true
    else begin
      Result := false;
      for i := Low(Columns) to High(Columns) do
        if n = Columns[i] then begin
          Result := true;
          Break;
        end; { If }
    end; { Else }
  end;

const
  DEFBORDER = 8;
var
  max, temp, i, n: Integer;
begin
  Assert(Assigned(Grid));
  Grid.Canvas.Font := Grid.Font;
  for n := 0 to Grid.Colcount - 1 do
    if ColInArray(n) then begin
      max := 0;
      for i := 0 to Grid.RowCount - 1 do begin
        temp := Grid.Canvas.TextWidth(Grid.Cells[n, i]) + DEFBORDER;
        if temp > max then
          max := temp;
      end; { For }
      if max > 0 then begin
        Grid.ColWidths[n] := Min(max, Grid.ClientWidth * 9 div 10);
      end;
    end; { If }
end; {SetGridColumnWidths  }
Benötigt system.math in der Uses-Klausel.
Peter Below

Geändert von peterbelow ( 9. Aug 2019 um 13:34 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 2 von 2     12   


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:59 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz