Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
LOCAL laEvents[ 1 ], loHeader, lcField, loColumn, lcSortOrder, loControl
LOCAL llFoundColumn, llAllowCellSelection, lnRecNo
*** First of all, see which column fired off this event
AEVENTS( laEvents, 0 )
loHeader = laEvents[ 1 ]
IF VARTYPE( loHeader ) = 'O'
*** First See if a ControlsSource was set for the column
WITH loHeader.Parent
lcField = ''
IF NOT EMPTY( .ControlSource )
*** Cool. Use it to decide how to sort the grid
IF NOT EMPTY( .ControlSource ) AND ( '.' $ .ControlSource ) AND NOT( '(' $ .ControlSource )
lcField = JUSTEXT( .ControlSource )
ENDIF
ENDIF
ENDWITH
*** we have a field - let's see if it already has a sort order set
*** if it does, it will have the appropriate picture in the header
lcSortOrder = ''
IF NOT EMPTY( loHeader.Picture )
lcSortOrder = IIF( LOWER( JUSTFNAME( loHeader.Picture ) ) == 'down.bmp', '', 'DESC' )
ELSE
*** See if there is a visual cue on any of the other grid
*** column headers and remove it if there is
FOR EACH loColumn IN This.Columns
FOR EACH loControl IN loColumn.Controls
IF LOWER( loControl.BaseClass ) == [header]
IF NOT EMPTY( loControl.Picture )
llFoundColumn = .T.
loControl.Picture = []
loControl.FontBold = .F.
EXIT
ENDIF
ENDIF
ENDFOR
IF llFoundColumn
EXIT
ENDIF
ENDFOR
ENDIF
*** if we have a field - let's sort
IF NOT EMPTY( lcField )
*** There seems to be a refresh issue here
*** because even though the data is in the cursor
*** it is not showing up in the grid after the sort
*** and it looks like it is related to AllowCellSelection being .F.
llAllowCellSelection = This.AllowCellSelection
This.AllowCellSelection = .F.
This.Refresh()
KEYBOARD '{CTRL+TAB}'
*** Check to see if the tag exists assume
*** that if there is a tag on this field, it has the same name as the field
IF IsTag( lcField, This.RecordSource )
lnRecNo = RECNO( This.RecordSource )
*** Go ahead and set the order for the table
SELECT ( This.RecordSource )
SET ORDER TO ( lcField )
This.SetFocus()
IF lnRecNo # 0
GO lnRecNo IN ( This.RecordSource )
ENDIF
*** And set the visual cues on the header
loHeader.Picture = IIF( EMPTY( lcSortOrder ), [..\graphics\up.bmp], [..\graphics\down.bmp] )
loHeader.FontBold = .T.
This.AllowCellSelection = llAllowCellSelection
ENDIF
ENDIF
ENDIF
*** now make sure that the dblclick method of all the contained text boxes
*** delegate to the grid's dblclick()
FOR EACH loColumn IN This.Columns
FOR EACH loControl IN loColumn.Controls
*** Now make sure we call te sortgrid method when we click on a header
IF LOWER( loControl.BaseClass ) = 'header'
BINDEVENT( loControl, 'Click', This, 'SortGrid' )
ENDIF
ENDFOR
ENDFOR
*-- Passed the name of an index tag returns true if it is a tag for the specified table. Uses table in the current work area if no table name is passed.
FUNCTION IsTag( tcTagName, tcTable )
LOCAL ARRAY laTags[1]
LOCAL llRetVal
*** Did we get a tag name?
IF TYPE( 'tcTagName' ) # 'C'
*** Error - must pass a Tag Name
ERROR '9000: Must Pass a Tag Name when calling ISTAG()'
RETURN .F.
ENDIF
*** How about a table alias?
IF TYPE( 'tcTable' ) = 'C' AND ! EMPTY( tcTable )
*** Get all open indexes for the specified table
ATagInfo( laTags, "", tcTable )
ELSE
*** Get all open indexes for the current table
ATagInfo( laTags, "" )
ENDIF
*** Do a Case Insensitive, Exact=ON, Scan of the first column of array
*** Return Whether the Tag is Found or not
RETURN ( ASCAN( laTags, tcTagName, -1, -1, 1, 7 ) > 0 )
ENDPROC