*********************************************************************** *** Changed By.: Marcia G. Akins on 19 August 2005 *** Reason.....: allow for multiple column sort *********************************************************************** CREATE CURSOR csrSortOrder (; iKey I, ; lUse L, ; cType C( 1 ), ; DisplayName C( 25 ), ; SortOrder I, ; FieldName C( 20 ), ; lDescending L ) INSERT INTO csrSortOrder VALUES ( 1, .T., [D], [Wanted By Date], 1, [Reqd_Date], .T. ) INSERT INTO csrSortOrder VALUES ( 2, .T., [C], [Vendor], 2, [Vendor], .F. ) INSERT INTO csrSortOrder VALUES ( 3, .T., [C], [Client], 3, [Client], .F. ) INSERT INTO csrSortOrder VALUES ( 4, .F., [N], [P.O. Number], 4, [PO_id], .F. ) INSERT INTO csrSortOrder VALUES ( 5, .F., [C], [List Name], 5, [List_Name], .F. ) INSERT INTO csrSortOrder VALUES ( 8, .F., [D], [Date Received], 6, [Date_Received], .T. ) INSERT INTO csrSortOrder VALUES ( 9, .F., [C], [Invoice Number], 6, [vendor_invoice_no], .T. ) SELECT csrSortOrder INDEX on SortOrder TAG SortOrder *********************************************************************** *** Changed By.: Marcia G. Akins on 20 August 2005 *** Reason.....: Set the default sort order *********************************************************************** Thisform.cOrderBy = [Reqd_Date DESCENDING, Vendor, Client]And this is the code that gets executed when you click on the Sort Now button:
LOCAL lcSortExpr SELECT csrSortOrder lcSortExpr = [] SCAN FOR lUse lcSortExpr = lcSortExpr + ALLTRIM( FieldName ) + ; IIF( lDescending, [ DESCENDING, ], [, ] ) ENDSCAN *********************************************************************** *** Changed By.: Marcia G. Akins on 01 September 2005 *** Reason.....: If they have no sort expression, leave in natural order *********************************************************************** IF EMPTY( lcSortExpr ) lcSortExpr = [PO_id] ENDIF *********************************************************************** IF RIGHT( lcSortExpr, 2 ) == [, ] lcSortExpr = LEFT( lcSortExpr, LEN( lcSortExpr ) - 2 ) ENDIF Thisform.cOrderBy = lcSortExpr *** Now reselect the items in the grid in the correct order SELECT * FROM csrPurchase_hdr ORDER BY &lcSortExpr INTO CURSOR qTmp NOFILTER SELECT csrPurchase_hdr ZAP APPEND FROM DBF( [qTmp] ) GO TOP IN csrPurchase_hdr Thisform.grdcsrPurchase_hdr.SetFocus()Details on how to implement the "Sort Order" grid with the mover bars is in the Kitbox Column I mentioned in my previous message.