* ********************************************************* * * * * 07/30/00 PREVIEWCHECKBOX.MPR 10:03:12 * * * ********************************************************* LPARAMETER toColumn DEFINE POPUP shortcut shortcut RELATIVE FROM MROW(),MCOL() DEFINE BAR 7 OF shortcut PROMPT "Sort" ON SELECTION BAR 7 OF shortcut SortBy( toColumn ) ACTIVATE POPUP shortcut *!* 2001.08.19 nf FUNCTION SortBy. Moved this functionality from the header *!* click() method to avoid conflicts with resizing the columns FUNCTION SortBy(toColumn) *!* First see if we already have a tag for this column LOCAL lnTags, loGrid, lcAlias, lnRecno, lvValue, loHeader PRIVATE plSuccess, lcExpr plSuccess = .T. lcExpr = JUSTEXT( tocolumn.CONTROLSOURCE ) *!* 2001.03.07 NF 4: Added protection on strings too long to index lvValue = EVALUATE( lcExpr ) IF VARTYPE( lvValue ) = "C" .AND. LEN( lvValue ) > 240 lvValue = "LEFT(" + lcExpr + ",240)" ELSE lvValue = lcExpr ENDIF FOR EACH loHeader IN toColumn.Controls IF LOWER( loHeader.BaseClass ) = "header" EXIT ENDIF *!* If we don't find a header, we're stuck. But that would be unlikely since *!* the intention of this PRG is to be run from the rightclick of a header. NEXT lni loGrid = toColumn.PARENT lcAlias = loGrid.RECORDSOURCE lnTags = TAGCOUNT( lcAlias ) SELECT (lcAlias) && Yes, it should be active, but just in case lnRecno = RECNO() IF loHeader.FONTBOLD IF DESCENDING() lcExpr = "INDEX ON " + lvValue + " TAG " + SUBSTR( lcExpr, 1, 10 ) + " ASCENDING" ELSE lcExpr = "INDEX ON " + lvValue + " TAG " + SUBSTR( lcExpr, 1, 10 ) + " DESCENDING" ENDIF &lcExpr ELSE lcExpr = "INDEX ON " + lvValue + " TAG " + SUBSTR( lcExpr, 1, 10 ) + " ASCENDING" &lcExpr loGrid.SETALL( 'FontBold', .F. ) *!* 2001.03.07 nf 3: If the indexing wasn't successful, don't bold the header. IF plSuccess .AND. !EMPTY(ORDER()) loHeader.FONTBOLD = .T. ENDIF ENDIF loGrid.REFRESH() LOCAL lcOrder lcOrder = ORDER() WITH loGrid.PARENT.Label2 .CAPTION = "Sorted by " + loHeader.CAPTION + IIF( DESCENDING(), ' (descending).', ' (ascending).' ) .VISIBLE = .NOT. EMPTY( lcOrder ) ENDWITH GOTO lnRecno ENDFUNC