Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing the width of text grid controls
Message
From
05/10/2001 12:22:48
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00564807
Message ID:
00564870
Views:
23
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform