Thread: FoxPro Some General Questions/Sort columns in Grid

Sort columns in Grid
true DBGrid

have this code in the header's click methos:

WITH This.Parent
  IF PEMSTATUS( .Parent, 'SetOrder', 5 )
    .Parent.SetOrder( JUSTEXT( .ControlSource ) )
  ENDIF
ENDWITH   

This code in the grid's SetOrder() method:


LPARAMETERS tcTag
LOCAL lnRecNo, laTags[ 1 ]
*** Make sure a valid tag name was passed
IF ! EMPTY( tcTag )
  *** Make sure we have the procedure file loaded so we can access the
  *** IsTag() function
  SET PROCEDURE TO Ch06 ADDITIVE
  WITH This
    *** Make sure it really is a tag for the grid's RecordSource
    *** Get all open indexes for the specified table
    ATagInfo( laTags, "", .RecordSource )
    IF ASCAN( laTags, tcTag, -1, -1, 1, 7 ) > 0
      lnRecNo = RECNO( .RecordSource )
      *** Go ahead and set the order for the table
      SELECT ( .RecordSource )
      SET ORDER TO ( tcTag )
      IF lnRecNo # 0
        GO lnRecNo IN ( .RecordSource )
      ENDIF
      .SetFocus()
    ENDIF
  ENDWITH               
ENDIF