INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Graphical User Interface

How do I resize a string grid column to fit the largest text in the cells? by djjd47130
Posted: 17 Nov 11

In a String Grid (TStringGrid), you may want to automatically resize a column to fit the longest string under that column. This procedure will do the resizing for you:

CODE

procedure ResizeCol(AGrid: TStringGrid; const ACol: Integer);
const
  MIN_COL_WIDTH = 15;
var
  M, T: Integer;
  X: Integer;
begin
  M:= MIN_COL_WIDTH;
  AGrid.Canvas.Font.Assign(AGrid.Font);
  for X:= 1 to AGrid.RowCount - 1 do begin
    T:= AGrid.Canvas.TextWidth(AGrid.Cells[ACol, X]);
    if T > M then M:= T;
  end;
  AGrid.ColWidths[ACol]:= M + MIN_COL_WIDTH;
end;
 

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close