Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sizing TStringGrid columns

Status
Not open for further replies.

Lorne50

Programmer
Dec 18, 2005
4
0
0
GB
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.
 
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...
 
Size on the heading - I know the heading is always wider than the data which is max a 3 digit integer.
 
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
 
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.
 
The code is fine, just add an offset (10 pixels should be enough)

/Daddy

-----------------------------------------------------
Helping people is my job...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top