I use a grid method I took from Paul Mrozowski 10 years ago called SaveSource and RestoreSource so you never have to hardcode like Rafael's example below. Check out the archives. I know I've posted it here in the past.

It's basically this:

this.pgf.pagData.grd.SaveSource()
this.RequeryData() && now requery/regenerate your cursor--using the same name as the grid expects; no workarounds needed
this.pgf.pagData.grd.RestoreSource()

hth,
--Mike


On 2015-06-18 13:20, Rafael Copquin wrote:
The best way to do this is thus:

Populate the grid on page 1 with the father records. This grid will
never loose its settings.

In the afterrowcolchange method of this grid put the following code:
(this code operates on each record of page 1 as you go up or down its grid)

     thisform.pageframe1.page2.grid1.recordsource = ''

     use in select('curChildren')

   ****  here goes your select statement to get the children records
(say you name it curChildren)

  select * from father table where fatherid = .... into cursor
curChildren nofilter

   with  thisform.pageframe1.page2.grid1
           .recordsource = 'curChildren'
          .column1.controlsource = 'curChildren.field1' && the name of
each field in your cursor
          .column2.controlsource = 'curChildren.field2'
          etc
  endwith

 thisform.pageframe1 .page2.refresh

BTW, the autofit property is used to make all records in a grid show
without truncation, but only in the part of the grid that you see at
any one time, so _it is not good for what you need_. You just click on
the top left of the grid and it refits itself to show the full length
of the contents in each column.



Rafael Copquin



El 18/06/2015 a las 12:16, Kevin Cully escribió:
I'm working on a VFP form and I don't think I'm using a best practice for AUTOFITting a grid. I've a pageframe with two pages, each page has a grid. Many of these parent records have zero child sales records and/or labor records. What's the best practice to get the grids to AUTOFIT reliably?

Grids are set as:
     ReadOnly = .T.
    AllowCellSelection = .F.

In the THISFORM.LOAD() event, I create a cursor that I leave open for the life of the form. When I navigate through the order records, I SQL SELECT the child records, select the cursor that was created in the LOAD(), ZAP it, and then append records from the cursor for the display of the child records. This saves me from using views, and the binding/unbinding problem with grids.

Here's the code I use to try to get that grid to autofit properly. This code is *after* I've reloaded the records in the child cursor.


    THISFORM.LockScreen = .T.
    && Lots of business stuff... including reloading the child cursor.
    THISFORM.LockScreen = .F.

    THISFORM.Pageframe1.Page1.grdSales.AutoFit()
    THISFORM.Pageframe1.Page2.grdLabor.AutoFit()
    THISFORM.Refresh()

The grids still aren't displayed with the optimized field sizes. Harumph. Thanks for any help.

[excessive quoting removed by server]

_______________________________________________
Post Messages to: ProFox@leafe.com
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/13d22a450a8c82eee8ad41920de53...@mbsoftwaresolutions.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to