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

Sizing TStringGrid columns

Sizing TStringGrid columns

(OP)
I have a stringgrid that contains text read from a file. The first row are column headings and I want to size the columns so the text fits. The following code creates columns that are about 10% too narrow - any idea how I can get it to fit?

ResultsGrid.Canvas.Font := ResultsGrid.Font;
for Col := 0 to ResultsGrid.ColCount - 1 do
ResultsGrid.ColWidths[col] :=
ResultsGrid.Canvas.TextWidth(ResultsGrid.Cells[Col, 0]);

Delphi XE3.

RE: Sizing TStringGrid columns

Do you want to size the column on the heading or to the largest value width in that column?

/Daddy

-----------------------------------------------------
Helping people is my job...

RE: Sizing TStringGrid columns

(OP)
Size on the heading - I know the heading is always wider than the data which is max a 3 digit integer.

RE: Sizing TStringGrid columns

Can you not simply add an offset? You would want the cols to be a little wider than the text anyway?

Steve: N.M.N.F.
If something is popular, it must be wrong: Mark Twain
That's just perfectly normal Paranoia everyone in the universe has that: Slartibartfast

RE: Sizing TStringGrid columns

(OP)
I can easily make it fit on my computer but will it fit for another user who has changed their DPI setting, or is using large fonts or is using Windows accessibility options? What I do not understand is why the code I posted does not work - in theory it should correctly size the text regardless of any Windows setting the user chooses but there is obviously something else going on and I am hoping somebody can tell me what that is.

RE: Sizing TStringGrid columns

The code is fine, just add an offset (10 pixels should be enough)

/Daddy

-----------------------------------------------------
Helping people is my job...

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

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