Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Programatically Determine List.ColumnWidths
Message
From
26/07/2007 14:10:24
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01243619
Message ID:
01243882
Views:
21
>Ok, I tried this, and I'm getting incorrect results.
>
>I have a cursor with 2 columns, ID and Caption. Their widths are 4 & 50.
>
>
>sColWidths = "0,"
>sFontName = .lstAssigned.FontName
>iFontSize = .lstAssigned.FontSize
>
>FOR iColumn = 1 TO FCOUNT()
>  iSize = TXTWIDTH(ALLTRIM(FIELD(iColumn)), sFontName, iFontSize)
>  sColWidths = sColWidths + TRANSFORM(CEILING(iSize)) + ","
>ENDFOR
>
>
>This results in sColWidths being "0,2,10,"

Now if you have only two columns, why would you need three numbers in th esColWidths?
sColWidths = ""
sComma=""
sFontName = .lstAssigned.FontName
iFontSize = .lstAssigned.FontSize
tm6=fontmetric(6, sFontName, iFontSize)

FOR iColumn = 1 TO FCOUNT()
  calculate max(TXTWIDTH(ALLTRIM(eval(FIELD(iColumn))), sFontName, iFontSize)*tm6) to iSize
  sColWidths = sColWidths+sComma + TRANSFORM(CEILING(iSize))
  sComma=", "
ENDFOR
Note that I'm taking eval() of the column, so it would measure the length of the actual content, not of the column's name, and I'm doing a Calculate Max() of it, so it would find the maximal length for all records, not just the current one. And the tm6 is the average character width that I forgot last time.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform