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

Re-sizing a grid

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
621
GB
I have a form class which re-sizes its controls when the form is re-sized.

To that end each control (Text box, label, grid &c) has properties in which can be saved its original width height, fontsize &c. Each control remembers these interesting values in its own Init() method. When the form is re-sized, it visits each control, recalculates the width, height &c of that control in proportion to the revised form size.

This works fine. I would also like to do a similar thing with the columns of the grid, and this is where I having a difficulty.

It was easy enough to subclass the grid itself to have these properties of its original width and height. However I would rather like to have a property for each column to remember its original column width. But I do not know how to do that: in my sub-classed grid I do not know how many columns there are going to be, so I cannot easily add this extra property to each column. As a kluge I have taken to using the comment field of each column (at run time, when I know how many columns there are) to hold this value, but this does not seem quite respectable.

Suggestions welcomed. Andrew
 
Andrew,

First of all, you can forget all that stuff about saving the original height and width. Almost all controls have an Anchor property. Just set to that property to indicate how you want to resize the control, and VFP will do it for you.

That said, that doesn't answer your question. You can use the grid's Anchor property to resize the grid as a whole, but that does not help with resizing the columns within the grid.

One solution would be to add a property to each column to hold its original width. You can do that at run time, even though you don't know how many columns there are. Something like this (not tested):

Code:
* In the Init of the grid, after you have assigned the RecordSource
FOR EACH oColumn in THIS.Columns
  oColumn.AddProperty("nWidth", 0)
ENDFOR

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
The anchor property unfortunately doesn't exist for a column object. you have the same problem with the ColunmnWidths property of a listbox, when you have a multi column listbox.

You can use the ResetToDefault() method to set back a default without storing it in extra properties, if you do that while you lock the screen this would work nicely enough.

Bye, Olaf.
 
AndrewMozley said:
in my sub-classed grid I do not know how many columns there are going to be, so I cannot easily add this extra property to each column

You can try adding the ColumnCount_assign event to the grid, and placing the code in it.

Respectfully,
Vilhelm-Ion Praisach
Resita, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top