Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Automatically size column widths in a grid
Message
From
11/09/2003 20:25:41
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00826986
Message ID:
00828374
Views:
13
Hi Rich,

Thanks for the very comprehensive reply and info! That did it!

Regards
Dennis

>>Is there a way to automatically size column widths in a grid (probably in the Init event?) by just supplying a property with a comma delimited list of fields? The columns must in a way be wide enough to contain the whole field width?
>
>Yes you can size column widths in code, but no, not with a comma delimited list.
>
>You would usually do it with a loop, checking the controlsource of the columns (or assigning them in the loop), checking the field size of that controlsource, and multiplying by FONTMETRIC(6,Grid.FontName,Grid.FontSize) to get the appropriate column width.
FOR lnColNum = 1 to grdMyGrid.ColumnCount
>	WITH grdMyGrid.Column[lnColNum]
>		.ControlSource = FIELD(lnColNum, "MyTable")
>		.Width = FSIZE(FIELD(lnColNum, "MyTable"), "MyTable") * FONTMETRIC(6, grdMyGrid.FontName, grdMyGrid.FontSize)
>	ENDWITH
>ENDFOR
>
>If you have a known list of widths you want to use (you must, if you wanted to use a comma-delimited list), you could just say:
WITH grdMyGrid
>	Column1.Width = 35
>	Column2.Width = 70
>	Column3.Width = 57
>ENDWITH
Previous
Reply
Map
View

Click here to load this message in the networking platform