this slowpoke moves

Edit StringGrid Cell Size

uses ExtCtrls, Grids

public
    { Public declarations }
    procedure AutoSizeCol(Grid: TStringGrid; Column: integer);
    procedure SizeColsToHeaders(Grid: TStringGrid);
    
//

procedure TForm1.SizeColsToHeaders(Grid: TStringGrid);
var
  Col: integer;
begin
  for Col := 0 to (Grid.ColCount - 1) do
    Grid.ColWidths[Col] :=
      Grid.Canvas.TextWidth(Grid.Cells[Col, 0]) + 150; // Größe in Pixel
end;

procedure TForm1.AutoSizeCol(Grid: TStringGrid; Column: integer);
var
  i, W, WMax: integer;
begin
  WMax := 0;
  for i := 0 to (Grid.RowCount - 1) do begin
    W := Grid.Canvas.TextWidth(Grid.Cells[Column, i]);
    if W > WMax then
      WMax := W;
  end;
  Grid.ColWidths[Column] := WMax + 150;  // Größe in Pixel
end;

// Zelle 1 verändern
procedure TForm1.Button1Click(Sender: TObject);
begin
  AutoSizeCol(StringGrid1, 1);
end;

// alle Zellen verändern
procedure TForm1.Button2Click(Sender: TObject);
var
  i: integer;
begin
  for i := 0 to StringGrid1.ColCount - 1 do
    AutoSizeCol(StringGrid1, 0);
end;

//  Spaltenbreiten an die Spaltenüberschriften anpassen
procedure TForm1.Button3Click(Sender: TObject);
begin
  SizeColsToHeaders(StringGrid1);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate