On 10/26/2010 1:58 PM, Rafael Copquin wrote:
> You always open tables or create cursors in the load event, unless you
>
> pass a collection or a XML or a value to the form, by which you create a
> cursor from a select based on the value passed. If you pass a collection
> or an object you generate the cursor from those. In all three cases you
> must use the init event of the form.
>
> On the other hand, it is always better to call another form making this
> one private data session, so whatever you do in that form does not mess
> up anything in the calling form.
>
> The fact that it is or not a modal form should not be the source of your
> problem.
>
> Remember that a grid is instantiated before the init of the form but
> after the load event of the form, so it will not be populated unless you
> open the tables first in the load event. If you have to open them in the
> init of the form, then you must, after you open the tables or cursors,
> do something like this, in the init of the form:
>
> thisform.grid1.recordsource = 'thecursorjustcreated' and you might have
> to populate the controlsource of each column of the grid with code like
> this:
>
> thisform.grid1.column1.controlsource = 'thecursorjustcreated.field1', etc


I built this code into my grid class to save and restore easily (along 
with Init to show how I left the class set the controlsources):

---------------------------
*SaveSource
LOCAL loColumn as Column

This.oColumnInfo = CREATEOBJECT("Collection")

FOR EACH loColumn IN This.Columns
     This.oColumnInfo.Add(loColumn.ControlSource)
     loColumn.ControlSource = .NULL.
ENDFOR

This.cOrigRecordSource = This.RecordSource
This.RecordSource = .NULL.


---------------------------
*RestoreSource
LOCAL liIndex as Integer, loColumn as Column

IF VARTYPE(This.oColumnInfo) <> "O"
    RETURN
ENDIF

liIndex = 1

This.RecordSource = This.cOrigRecordSource

FOR EACH loColumn IN This.Columns
     loColumn.ControlSource = This.oColumnInfo.Item[liIndex]
     liIndex = liIndex + 1
ENDFOR

---------------------------
* Init
LOCAL loException as Exception
TRY
        IF TYPE("oUtils.oSettings.cHighlightForeColor") = "C" AND 
!EMPTY(oUtils.oSettings.cHighLightForeColor) THEN
                this.HighlightForeColor = 
EVALUATE(oUtils.oSettings.cHighlightForeColor)
        ENDIF
CATCH TO loException
        * ignore...just trap quietly...could report to MBSS later if desired
        IF _vfp.StartMode = 0 THEN && developer should be alerted when in dev 
mode
                MESSAGEBOX("Problem setting gridhighlightforecolor for " + 
this.Name,16,"Color setting problem.")
        ENDIF
ENDTRY
TRY
        IF TYPE("oUtils.oSettings.cHighlightBackColor") = "C" AND 
!EMPTY(oUtils.oSettings.cHighLightBackColor) THEN
                this.HighlightBackColor = 
EVALUATE(oUtils.oSettings.cHighlightBackColor)
        ENDIF
CATCH TO loException
        * ignore...just trap quietly...could report to MBSS later if desired
        IF _vfp.StartMode = 0 THEN && developer should be alerted when in dev 
mode
                MESSAGEBOX("Problem setting gridhighlightforecolor for " + 
this.Name,16,"Color setting problem.")
        ENDIF
ENDTRY

IF this.lSetColumns THEN
        LOCAL loColumn as Column
        FOR EACH loColumn IN this.Columns
                loColumn.ControlSource = this.RecordSource + "." + loColumn.Name
        ENDFOR
ENDIF && this.lSetColumns


I believe I got the Save and Restore from Paul Mrozowski back in 2006 
iirc.



-- 
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/[email protected]
** 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