Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid with automatically adjusting column widths.
Message
From
27/07/1999 08:11:24
Kenneth Downs
Secure Data Software, Inc.
New York, United States
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00246416
Message ID:
00246500
Views:
13
Barbara and Elgin,

PMFJI, but I just wanted to toss in a couple of warnings about using FontMetric.

Given a basic routine something like this:
WITH MyForm....MyGrid
  lnFontMetric = FontMetric(6,.FontName,.FontSize)
  lnFontMetric = lnFontMetric * 1.3  &&--If using proportional fonts

  FOR i = 1 TO .ColumnCount
    .Columns(i).width = ;
       MAX( LEN(.columns(i).header1.caption),;
            LEN(.columns(i).controlsource)) *;
       lnFontMetric
  ENDFOR
ENDWITH
Some notes:
1. The columns and their controls must have the same font as the grid itself for the above code to work.
2. If using Arial or any other proportional font, you almost always have to put in some type of multiplier, since FontMetric returns only an average width, and it fails on headers that contain wide letters.
3. The above code will work for checkboxes, but not for such things as spinners or comboboxes. I generally add two to the length of the control to accomodate the buttons on those controls.
4. The code above assumes character fields, you need a case statement for other types. For that case statement, keep in mind things like the fact that the field length for a DateTime is 8, but the display width is up to 22 characters: MM/DD/YYYY_HH:MM:SS_XM. Same for a date, the field width is 8, but the display width is 10 with century set on.
5. Also, if you are using format "R" for numerics, a field of width 10, with a picture of "9,999,999,999" actually needs a display width that matches its picture (13), not its field width (10).

Hope this helps...

>Barbara,
>
>Thanks for the suggestion. I'm not familiar with the FontMetric() function, but I'm going read up on it now.
>
>Thanks
>Elgin
>
>
>>Elgin,
>>Once your grid has been filled you can run through the columns with a for/next loop checking the width of both header text and field length with FontMetric(). Then set the column width to the larger of the two.
>>
>>HTH
>>Barbara
>>
>>>I am designing a form that has a grid where the record source is the alias of the currently open table and the column count is set to -1.
>>>
>>>I would like for the column widths to automatically adjust to the widest item in the column, either the Heading OR the widest data displayed in the column.
>>>
>>>In general, is this the proper way to design a grid of that nature? Do I have to specify a "column count" and manually set the width of each?
>>>
>>>Thanks.
>>>
>>>Elgin Rogers Jr
>>>Epic Solutions.
Previous
Reply
Map
View

Click here to load this message in the networking platform