>Is it possible to optimize the width of text grid controls in a program?
>
>The scenario is that I have a grid where there is just enough room on the screen to display each row using the existing maximum length of data contained in each field. For example, when displaying a product's data, I found the item with the longest description and manually sized the control accordingly. I followed the same procedure for other read only controls. As mentioned above, when completed, the row just fits on the screen without scrolling.
>However, the data is not static and I would like the controls to automatically resize themselves everytime the form is run.
>Is this practical? possible?
>TIA.
Allan,
Larry is right about overhead. Leaving consideration of it up to you here is some code for a particular column :
With oColumn
lcType = type(.Controlsource)
lnDotPos = at('.',.Controlsource)
lcField = substr(.Controlsource,lnDotPos+1)
lcTable = left(.Controlsource,lnDotPos-1)
lcSampleText = ''
lcFont=.FontName
lnSize=.FontSize
Do case
Case lcType = "C"
Select max(txtwidth(trim(&lcField), lcFont, lnSize)) ;
from (lcTable) ;
into array arrTemp
.Width = .Parent.Gridlinewidth*2 + ;
arrTemp[1,1] * fontmetric(6, .FontName, .FontSize)
Case lcType = "M"
lcSampleText = replicate("HI",20)
Case lcType $ "DT"
lcSampleText = transform(eval(.Controlsource))
Otherwise
Endcase
If !empty(lcSampleText)
.Width = .Parent.Gridlinewidth*2 + ;
txtwidth(lcSampleText, .FontName, .FontSize) * ;
fontmetric(6, .FontName, .FontSize)
Endif
Endwith
Cetin