Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting ColumnWidths In Code
Message
From
22/07/2005 21:06:34
Dragan Nedeljkovich
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01034883
Message ID:
01035336
Views:
13
>Ok guys, thanks for all the help thus far.
>
>The listbox columns will be read in from a table.
>
>So if the width in the table is 100, and I set the column
>header with to 100, then the columnwidth in the list to 100,
>the list column is actually wider than the header visually.
>
>How do I use TXTWIDTH() and FONTMETRIC() knowing that I
>want to the column to be 100? There is no text here to
>use with TXTWIDTH().

The width of what exactly in the table? The field, measured in bytes? YMMV greatly, depending on the case (upper or lower) of strings there.
?txtwidth(replicate("i",100),"Arial",10)
50.00
?txtwidth(replicate("W",100),"Arial",10)
216.667
The problem is similar to the famous Re: Low level file functions to get the number of lines Thread #41205 Message #41220 and the incredible response in message #41229.

You may try to
use yourtable
calculate max(txtwidth(alltrim(yourfield1), "Arial",10)), ... ;
   to nMaxCharsFld1, nMaxCharsFld2, ...
That would give you some orientation on the max number of character units (in, basically, foxels - still need to multiply with fontmetric() as David and Sergey said). That would give you a safe width that's guaranteed (more or less) to display your content. Now what will you do when there aren't enough pixels... up to you.

Also, you need to add the margin into the calculation. Though help says that only ComboBox | EditBox | Spinner | TextBox have .margin property, it doesn't necessarily mean that listbox has no margin. It only has no .margin property. You may try to add or subtract 2 or 3 pixels to/from each column's width to make it match your above-the-box control.

Welcome to the wonderful world of pixel calculation :).

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