Announcement

Collapse
No announcement yet.

TStringGrid : optimale Spaltenbreite

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • TStringGrid : optimale Spaltenbreite

    Hallo,<br>ich möchte für jede Spalte in einem TStringGrid die optimale Spaltenbreite berechnen. Wie gehe ich da am geschicktesten vor ?<br> Udo Böhm

  • #2
    Hallo Udo,<br>probier mal folgende procedure<br>

    <pre>
    procedure CalcOptColumnWidth(sg : TStringGrid);
    var
    aRow,aCol : Integer;
    aCellTextWidth : Integer;
    aColWidth : Integer;
    begin
    For aCol:=0 to sg.ColCount-1 do
    begin
    aColWidth:=0;
    For aRow:=0 to sg.RowCount-1 do
    begin
    aCellTextWidth:=sg.Canvas.TextWidth(sg.Cells[aCol,aRow]);
    If aCellTextWidth>aColWidth then
    aColWidth:=aCellTextWidth;
    end; // For aRow:=0 to sg.RowCount-1 do
    sg.ColWidths[aCol]:=aColWidth+4;
    end; // For aCol:=0 to sg.ColCount-1 do
    end;
    </pre>
    <br>
    Viel Spass<br>:-) Jens Schuman

    Comment

    Working...
    X