My grid class is as follows, and allows me to just set the column names and it takes care of naming the columns controlsources accordingly. Also, the SaveSource and RestoreSource calls are used around my call back to the DataObj to refresh my data. I never have to hard code any grid stuff. Been working great for 10+ years.

**************************************************
*-- Class:        grdbase (c:\dev\fabnet\classes\mjbbase.vcx)
*-- ParentClass:  grid
*-- BaseClass:    grid
*-- Time Stamp:   12/07/14 10:49:04 PM
*
DEFINE CLASS grdbase AS grid


        AllowHeaderSizing = .F.
        AllowRowSizing = .F.
        DeleteMark = .F.
        Height = 200
        Width = 320
        HighlightBackColor = RGB(255,255,40)
        HighlightForeColor = RGB(0,0,0)
        HighlightStyle = 2
        *-- used in SaveSource/RestoreSource
        ocolumninfo = .F.
        *-- used in the SaveSource/RestoreSource methods
        corigrecordsource = .F.
        *-- set to .T. to have Init event set column controlsources
        lsetcolumns = .F.
        *-- in dblclick method, calls thisform.EditRecord if exists
        leditondblclick = .T.
        *-- XML Metadata for customizable properties
_memberdata = [<VFPData><memberdata name="leditondblclick" display="lEditOnDblClick"/><memberdata name="lregisterasogrid" display="lRegisterAsOGrid"/><memberdata name="ckey" display="cKey"/><memberdata name="restoresource" display="RestoreSource"/><memberdata name="savesource" display="SaveSource"/><memberdata name="corigrecordsource" display="cOrigRecordSource"/><memberdata name="lsetcolumns" display="lSetColumns"/><memberdata name="ocolumninfo" display="oColumnInfo"/></VFPData>] *-- set to .T. to have grid register itself as thisform.oGrid in grid.Init event.
        lregisterasogrid = .T.
        *-- active index for grid (mjb 04-13-14)
        ckey = ""
        Name = "grdbase"


        PROCEDURE savesource
                LOCAL loColumn as Column

                This.oColumnInfo = CREATEOBJECT("Collection")

*** mjb 12/07/2014 - for some reason, columncount was going to zero!?!?
                IF this.ColumnCount = 0 THEN
                        SET STEP ON
                        this.Init()
                ENDIF && this.ColumnCount = 0

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

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


        *-- restore previous column definitions
        PROCEDURE 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
        ENDPROC


        PROCEDURE DblClick
IF this.lEditOnDblClick AND PEMSTATUS(thisform,thisform.cEditMethod,5) AND NOT EMPTY(thisform.cEditMethod) THEN
                        LOCAL lcCmd as String
                        lcCmd = [thisform.] + thisform.cEditMethod + [()]
                        &lcCmd
                ENDIF
        ENDPROC


        PROCEDURE 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.lRegisterAsOGrid THEN
                        thisform.oGrid = this
                        IF PEMSTATUS(thisform,"cAlias",5) AND NOT 
EMPTY(thisform.cAlias) THEN
                                this.RecordSource = thisform.cAlias
                        ENDIF
                ENDIF

                IF this.lSetColumns AND NOT EMPTY(this.RecordSource) THEN
                        LOCAL loColumn as Column
                        FOR EACH loColumn IN this.Columns
                                loColumn.ControlSource = this.RecordSource + 
"." + loColumn.Name
                        ENDFOR
                ENDIF && this.lSetColumns
        ENDPROC


ENDDEFINE
*
*-- EndDefine: grdbase
**************************************************




On 2015-08-04 11:32, Kevin Cully wrote:
I use SPT and I never allow for editing of values in a grid.  Here's
how I've approached the issue...

In the LOAD event I do my first SPT with a "SELECT field1, field2,
field3 FROM myTable WHERE 1=2;" into a cursor (lets call it c_MyTable)
that lives throughout the life of the form.
In the INIT event, I bind my grid to c_MyTable and set my column headers.
In that same INIT, I will do my default search calling
THISFORM.SearchMyTable( THISFORM.txtSearch.Value ) which should be
empty at this point.
If someone types into the THISFORM.txtSearch field, in the
InteractiveChange event, it calls through THISFORM.SearchMyTable(
THISFORM.txtSearch.Value ).
In the THISFORM.SearchMyTable() method, it does something like this....

PARAMETER tcSearch
lcCommand = "SELECT field1, field2, field3 FROM myTable WHERE
TRIM(field1) LIKE '" + tcSearch + "%' ORDER BY field1 LIMIT 1000;"
llSuccess = goApp.SPTSelect( lcCommand, 'tempMyTable' )

DO CASE
    CASE NOT USED("tempMyTable")
        && Problem!
    CASE NOT USED("c_MyTable")
        && Problem!
    OTHERWISE
       SELECT c_MyTable
       && Make sure SET SAFETY IS OFF
       ZAP
       APPEND FROM DBF(tempMyTable)
       USE IN tempMyTable
       && Refresh the grid and set LockScreen = .F.
ENDCASE

I can get clickable headers as long as it works with the limit of 1000
records above by modifying the grid or using a subclass. Worked for me
for years and years.

HTH.

CULLY Technologies, LLC
http://cullytechnologies.com
http://cully.biz

On 08/04/2015 11:05 AM, Dave Crozier wrote:
Just asking those of you out there who use SPT with an SQL Back End how you handle Grid refreshes (refreshing the underlying data) when browsing tables on the main data server assuming that you may well stay on a browse window when somebody else may well update the data.

I am just trying to write a small set of demo forms using Remote views, Cursor Adapters as well as SPT for Tom here in order to better explain the advantages/disadvantages of each data access method. Obviously with cursor adapters you can issue a cursorRefresh() against the back end and with remote views you can do a requery() against the view. The only method I use with SPT is in fact to issue the "select..." again.

Anyone got any better suggestions apart from using stored procedures on the back end which I don't really want to use.

The nice thing about the remote view and cursor adapter method is that the currently selected row gets preserved in the grid. I have tried the same in SPT by saving the current row and navigating to it after the re-select but it causes screen glitches regardless of using _Screen.Lockscreen unless anyone else has a better idea!

Dave



--- StripMime Report -- processed MIME parts ---
multipart/alternative
   text/plain (text body -- kept)
   text/html
---

[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
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/[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