Bill Anderson wrote:
> Now I'm trying to (in essence -- I'm using the VFE framework) is clear out
> the grid RecordSource's cursor and APPEND from the temp cursor. This
> "works", but doesn't display correctly when I'm in the BindEvent code.

I built my own grid header/sort functionality years ago (before BINDEVENT). I 
subclassed Header, trapped the click(), and sent it to self.Parent.Parent (the 
grid) 
to process.

I remember running into refresh issues and had to detach the rowsource before 
sorting, then reattach, and then change the row number. Or something. Oh hell 
here's 
the code (I'm embarrassed by its ugliness, but it does work):

{{{
* called by column.setindexorder(), which is usually called by
* header.setindexorder(), which is usually called by header.click()
* when the user wants to increment the index order of the column

LPARAMETERS corder

LOCAL lretval, crecordsource, nrecno

IF VARTYPE(m.corder) <> "C"
   corder = ""
ENDIF

crecordsource = this.RecordSource


IF EMPTY(m.corder) OR TAGNO(m.corder, "", m.crecordsource) > 0
   * If the order tag is empty, we need to set order to ""
   * If the order tag was found, set order to it
   * All the run-around below is to make sure that
   *   1) we end up on the same record as we started on
   *   2) the record we end up on is in the middle of the grid, not the very 
top.

   this.unbinddata(.T.)

   nrecno = RECNO(m.crecordsource)
   SET ORDER TO (m.corder) IN (m.crecordsource)
   GO TOP IN (m.crecordsource)

   this.binddata(.T.)

   IF m.nrecno > 0 AND m.nrecno <= RECCOUNT(m.crecordsource)
     GO (m.nrecno) IN (m.crecordsource)
   ENDIF

   this.refresh

   lretval = .t.

ELSE
   * tag wasn't found
   lretval = .f.
endif


RETURN (m.lretval)
}}}


Here's binddata():

{{{
* binds the grid to the datasource, and each column to it's
* controlsource

* This method gets called automatically if this.autobinddata == .T.

* If you ever need to close the cursor to which this grid is bound
* (during a view requery, for example, done from a different object)
* you'll want to first call this.unbinddata, do your stuff, and then
* do a this.binddata again.
LPARAMETERS lnosetorder
LOCAL ncount, nrows, colderr


IF !EMPTY(this.gridrecordsource) AND USED(this.gridrecordsource)

   * The grid recordsource must be set before the column controlsource,
   * which results in the columns being temporarily assigned to arbitrary
   * fields.  Set lockscreen to prevent flickering:
   thisform.LockScreen = .t.

   WITH this
     .recordsource = this.gridrecordsource
   ENDWITH


   * Set the column controlsources:
   FOR ncount =  1 TO this.ColumnCount


     WITH this.Columns[m.ncount]
       ccontrolsource = this.acolumns[m.ncount,4]

       IF !EMPTY(m.ccontrolsource)
         .controlsource = ALLTRIM(this.gridrecordsource) + "." + 
m.ccontrolsource
       ENDIF

     ENDWITH

   ENDFOR

   IF VARTYPE(m.lnosetorder) == "L" AND m.lnosetorder == .T.
     * do nothing
   ELSE


     * I'm not sure why I did the below originally, but if it
     * is uncommented we will always end up on the last record
     * when we requery.
*     SET ORDER TO (this.currentindexorder) IN (this.RecordSource)


     * If we were just now changing order, this block won't run.
     * But if we just requeried, we need to now re-set the index order
     * of the view and go to the top of the view:
*    =info("current indexorder: " + this.currentindexorder)

     DO case

       CASE !EMPTY(this.currentindexorder)
         TRY    && sometimes the tag isn't found, don't know why
           SET ORDER TO (this.currentindexorder) IN (this.RecordSource)
         CATCH
*          =info("Error in binddata")
         ENDTRY

       CASE this.defaultsortcolumn > 0 AND this.ColumnCount >= 
this.defaultsortcolumn ;
       AND PEMSTATUS(this.Columns(this.defaultsortcolumn), "heagrid", 5)
         this.Columns(this.defaultsortcolumn).heagrid.click()
*                this.ActiveColumn = this.Columns(this.defaultsortcolumn)*
*                KEYBOARD "{F2}"

     ENDCASE


     nrecno = RECNO(this.gridrecordsource)

     IF this.lFirstrequery
       IF this.cinitialrecord == "top"
         GO TOP IN this.gridrecordsource
       ELSE
         GO BOTTOM in this.gridrecordsource
       ENDIF

       this.lFirstRequery = .F.
     ELSE
       GO TOP IN this.gridrecordsource
       IF m.nrecno <= RECCOUNT(this.gridrecordsource)
         GO (m.nrecno) IN this.gridrecordsource
       ELSE
         * There must have been no records
       ENDIF

     ENDIF

     this.doscroll(2)

   ENDIF

   thisform.LockScreen = .f.

ELSE

   * this.gridrecordsource isn't  filled in or the cursor doesn't exist
   *=stop("The grid's record source isn't valid - notify Paul.")
ENDIF

this.SetAll("Visible", .T.)
}}}


and unbinddata():

{{{
* unbinds the grid from the datasource, and each column from it's
* controlsource

* If you ever need to close the cursor to which this grid is bound
* (during a view requery, for example, done from a different object)
* you'll want to first call this.unbinddata, do your stuff, and then
* do a this.binddata again.
LPARAMETERS lnosetorder

LOCAL ncount


IF !EMPTY(this.gridrecordsource)

   IF VARTYPE(m.lnosetorder) == "L" AND m.lnosetorder == .T.
     * do nothing / caller doesn't want us to touch the
     * index order (this.setindexorder for example)
*    this.currentindexorder = ORDER(this.RecordSource)  && test 2/22/02
   ELSE
     * Save the current index order to reset
     * later in this.binddata()
     IF USED(this.gridrecordsource)
            this.currentindexorder = ORDER(this.gridrecordsource)
        ENDIF
   ENDIF


   * Set the column controlsources:
   FOR ncount =  1 TO this.ColumnCount

     WITH this.Columns[m.ncount]

       .controlsource = ""

     ENDWITH

   ENDFOR



   WITH this
     .recordsource = " "
   ENDWITH

ELSE

   * this.gridrecordsource isn't  filled in or the cursor doesn't exist
   =stop("Please notify Paul: problem with unbinddata()")
ENDIF

}}}

_______________________________________________
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