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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid auto-sizing 1

Status
Not open for further replies.

wgcs

Programmer
Mar 31, 2002
2,056
EC
VFP8 now has auto-sizing columns, which is great, however, it seems that if you change the fontSize of the grid, then all the columns immediately resize, regardless of the setting of AllowAutoColumnFit

It does a pretty good job of sizing the columns, so I wouldn't complain, except where it comes to CheckBoxes or Spinner controls in the grid.

What happens is that I have several columns that have checkboxes (or spinners) in them, deliberately sized to 30 pixels wide, and when the grid's FontSize is changed, they all jump to about 100 pixels wide (much wider than the contained control).

Does anyone know of how to change the fontSize of a grid without this side affect?

(I just tried to create a plain-vanilla form with just a grid on it to reproduce the problem... and it doens't do the same thing. However my application stubbornly ALWAYS does this!)
 
Hi wgcs,

There are some issues related to this and I am not comfortable either with the auto resizing. I also read in MS site that some issues are there. But those remarks were read by me in the initial days of VFP8.

Since I continued from VFP7 where I had my own comfortable resizing class, I never bothered removing those and adapting VFP8's builtin auto resizing.

So I rely on my own resize class, since probable bug is present on this.

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Hi Ramani,

I'm glad I'm not alone in dealing with this. I do have my own resizing methods, but I can't seem to find a way to turn off the built in VFP8 resizing of the columns when the font size gets changed.... Maybe I have to leave GRID.FontSize the same and just change GRID.Column1.Spinner1.FontSize, etc
 
Hi

Have you set the property AllowAutoColumnFit for the grid to 2.

You can prevent the automatic resizing of a particular column by setting the Resizable property of that column to False (.F.).

:)

____________________________________________
ramani - (Subramanian.G) :)
 
Wgcs,

I've also struggled a bit with auto-sizing.

Have you tried calling the Autofit method after you apply the font change?

In general, I've found that you need to call Autofit after you make any change that could affect the column widths. In my present application, I am programmatically sizing the grid each time it is refreshed. I found that that overrode the autofitting, but calling Autofit after resizing solved the problem.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
It seems that "autofit" is automatically called after changing the font: I didn't even know about that method, and I wasn't calling it.

I turned off AllowAutoColumnFit (set it to 2) and it still auto-sizes the columns when the font is programmatically changed (which happens, on my forms, as the form is resized... which resizing is done once immediately after the form is instantiated (in init) to make it fill the width of the screen)

I think this statement in Help on AutoFit sums up our problems:
For Column objects, AutoFit works only with TextBox controls. When a column resizes, the Resize event for that column fires

I tried putting NODEFAULT in AutoFit, but that didn't do anything; it's not an event: it seems that changing the grid.fontsize doesn't "fire" AutoFit, but, behind the scenes, calls the same code that the AutoFit method calls.

So far, the only thing I've been able to find that keeps the checkbox columns from becoming 100 pixels wide is to turn off my font auto-sizing, and leave it always with the small font which would be appropriate for a 640X480 screen. Perhaps I can intercept grid.FontSize_assign and save the column widths, then restore the widths after the assignment?... I'll try that..
 
Yes!!!

That does it: A little ugly, but it seems to be the only way.

I Added a property to my grid class: AllowAutoSizeOnFontChange

And I added this as grid.FontSize_assign:
Code:
LPARAMETERS vNewVal
IF THIS.AllowAutoSizeColumnsOnFontChange 
  THIS.FontSize = m.vNewVal
ELSE
  LOCAL loColWid AS Collection
  loColWid = CREATEOBJECT('Collection')
  FOR lnI = 1 TO THIS.ColumnCount 
    loColWid.Add(THIS.Columns(lnI).Width)
  ENDFOR
  THIS.FontSize = m.vNewVal
  FOR lnI = 1 TO loColWid.Count
    THIS.Columns(lnI).Width = loColWid.Item(lnI)
  ENDFOR
ENDIF

(beautify collection class... why didn't we have it sooner!?)
 
Well done. Glad you've got it sorted.

Re grid beautifier classes ... What I am trying to do at the moment is to programmatically fill the grid, then autosize it, then change the width of the grid so that the auto-sized columns exactly fill the space (IOW, so there is no surplus space over to the right).

Seems like a good case for a generic class, incorporating both your techniqes and mind.

Mike'

Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Sounds like a nice class... not too hard to put together.

I usually lay out my grid to look appealing in my form: if the grid suddenly got narrower, things wouldn't lay out right... and there's the potential for the grid to auto-size wider than the whole form. If it stops at the edge of the form, don't forget to specify margin to keep it looking nice...

(btw, I noticed I missed "lnI" in the LOCAL statement in my code snippet, if anywone cares...)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top