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!

How can i autofit grid columns

Status
Not open for further replies.

kosta

Programmer
Feb 9, 2001
186
0
0
CA
Hi All,
how can i autofit grid columns programmatically.

TIA Soykan OEZCELIK
Comp.Prog / MSFoxPro Programmer Developer
soykanozcelik@web.de
ICQ#93291682
 
Here's a very rudimentary beginning, maybe you can build from it. Put this code in the click of a resize button or something to test it. If you want to be able to double-click on a grid column separator, you will have to use MROW(), MCOL(), GridHitTest etc., to handle that.

*...
Code:
FOR zzz = 1 TO MyForm.Grid1.COLUMNCOUNT
   cColMac = 'column' + ALLTRIM(STR(zzz))
   MyForm.Grid1.&cColMac..WIDTH = ;
      TXTWIDTH(MyForm.Grid1.&cColMac..text1.TEXT, 'Arial', 10) *;
      FONTMETRIC(6, MyForm.Grid1.&cColMac..FONTNAME, MyForm.Grid1.&cColMac..FONTSIZE)  
NEXT
*...

You can try changing 
FONTMETRIC(6, MyForm.Grid1.&cColMac..FONTNAME, ;
   MyForm.Grid1.&cColMac..FONTSIZE)  

-to-

FONTMETRIC(6, MyForm.Grid1.&cColMac..FONTNAME, ;
   MyForm.Grid1.&cColMac..FONTSIZE)
+ 2

or something if you want a little slack in the columns.
Dave S.
 
Or upgrade to VFP when it is available, which will probably be in 4-6 wks. It was released to manufacturing Jan 31. VFP 8 has this feature built-in.

Hope that helps!

-- Ed
-- Get great VFP support in a new forum filled with Microsoft MVPs!
--
 
Ed,

Yes but, there is there is still a 2.x forum out there. Safe to say there will be a lot of folks who don't/won't/can't.
We're going to supporting this 'old' stuff for years to come. :)
Dave S.
 
Sure, there are 2.x sites out there, but a) 2.x doesn't have grids and b) this is a VFP forum [smile]

-- Ed
-- Get great VFP support in a new forum filled with Microsoft MVPs!
--
 
I just meant that since there are still people using 2.x who, for whatever reason aren't upgrading to VFP, there will probably be a lot of folks who won't be upgrading to VFP 8 in the near future.
Dave S.
 
By the way Ed, best of luck on the forum. It's looks good so far. [thumbsup2]
Dave S.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top