I'll remind you of the grid class from the ProFox downloads section:
http://leafe.com/download/grdbase.prg
Also, I use this method call from the Header1.Click event usually,
calling thisform.ToggleSortOrder2(this.parent) && where this.parent is
the Column
PARAMETERS toColumn
this.cOrder = toColumn.Name && mjb 05-02-14
*** mjb 04/14/14 - took from HDIRT's frmbase togglesortorder method
LOCAL loException as Exception, lnRegColor as Integer, lnSelColor as
Integer, lcCmd as String, lnOldArea as Integer, liNumTags as Integer, ;
lcTagName as String, lcSeekValue as String, oColumn as Column,
lcCursor as String, loGrid as Grid, lcAscDesc as String
LOCAL ARRAY laTags[1]
lnOldArea = SELECT() && save current work area
lnRegColor = RGB(0,0,0) && could make this meta-data later too
lnSelColor = RGB(0,0,255)
lcOrder = toColumn.tag
IF this.lCreateTagOnFly AND EMPTY(lcOrder) THEN
lcOrder = toColumn.Name
toColumn.Tag = lcOrder
ENDIF
loGrid = toColumn.Parent
lcCursor = loGrid.RecordSource
IF !EMPTY(lcOrder) AND !EMPTY(lcCursor) THEN
SELECT (lcCursor)
TRY
*** mjb 08/09/2012 - see if index exists and add it on-the-fly if
necessary
liNumTags = ATAGINFO(laTags)
IF LEN(lcOrder) > 10 OR GETWORDCOUNT(lcOrder) > 1 THEN
IF NOT USED("TagsCursor") THEN
CREATE CURSOR TagsCursor (cCursor C(50), cOrder
C(75), cTag C(10))
INDEX on cCursor + cOrder TAG MyOrder
ENDIF
lcSeekValue = PADR(lcCursor,50) + PADR(lcOrder,75)
IF SEEK(lcSeekValue,"TagsCursor","MyOrder") THEN &&
grab tag name
lcTagName = ALLTRIM(TagsCursor.cTag)
ELSE && not found yet...create tag and add to cursor
lcTagName = SYS(2015)
INSERT INTO TagsCursor VALUES
(lcCursor,lcOrder,lcTagName)
ENDIF && SEEK(..)
ELSE && ok length..use fieldname passed
lcTagName = lcOrder
ENDIF && LEN(lcOrder) > 10
IF ASCAN(laTags,UPPER(lcTagName)) = 0 THEN && tag doesn't
exist...create it on the fly
IF GETWORDCOUNT(lcOrder) = 1 THEN && just simple tag
lcCmd = "INDEX ON " + lcOrder + " TAG " +
lcTagName + [ ASCENDING]
ELSE && expression built
* set lcTagName to be LAST word in command
which is tag name
lcTagName =
GETWORDNUM(lcOrder,GETWORDCOUNT(lcOrder))
IF INLIST(UPPER(lcTagName),'ASCENDING','DESCENDING','ASC','DESC')
THEN && get word prior
lcTagName =
GETWORDNUM(lcOrder,GETWORDCOUNT(lcOrder)-1)
ENDIF &&
INLIST(UPPER(lcTagName),'ASCENDING','DESCENDING','ASC','DESC') THEN &&
get word prior
* need to update TagsCursor since redefining tag name set there
earlier
IF SEEK(PADR(lcCursor,50) + PADR(lcOrder,75),"TagsCursor","MyOrder")
THEN
REPLACE cTag WITH lcTagName IN
TagsCursor
ELSE
SET STEP ON
* shouldn't happen
ENDIF
lcCmd = lcOrder
ENDIF
SELECT (lcCursor)
&lcCmd
ENDIF && ASCAN(laTags,UPPER(lcTagName)) = 0
SET ORDER TO (lcTagName) IN (lcCursor) && mjb 12-18-14
*** mjb 05/17/2014 - grabbed from ToggleSortOrder as it wasn't toggling
asc/desc as I expected
IF ORDER() = ALLTRIM(UPPER(lcTagName)) THEN
IF this.Visible THEN
IF this.cAscDesc = 'ASCENDING' THEN
SET ORDER TO (lcTagName) IN (lcCursor)
DESCENDING
this.cAscDesc = "DESCENDING"
ELSE
SET ORDER TO (lcTagName) IN (lcCursor)
ASCENDING
this.cAscDesc = "ASCENDING"
ENDIF && DESCENDING()
ELSE
IF NOT EMPTY(this.cAscDesc) THEN
lcAscDesc = ALLTRIM(this.cAscDesc)
SET ORDER TO (lcTagName) IN (lcCursor)
&lcAscDesc
this.cAscDesc = 'ASCENDING'
ENDIF && NOT EMPTY(this.cAscDesc)
ENDIF && this.visible
ENDIF && ORDER() = ALLTRIM(UPPER(lcTagName))
SELECT (lcCursor)
LOCATE && mjb 03-01-05 send to top when changing order
FOR EACH oColumn IN loGrid.Columns
oColumn.Header1.FontBold = LOWER(oColumn.Tag) =
LOWER(lcOrder)
IF oColumn.Header1.FontBold THEN && make backcolor use different
color to show selected order column (mjb 08-16-05)
oColumn.Header1.ForeColor = lnSelColor
ELSE
oColumn.Header1.ForeColor = lnRegColor
ENDIF
ENDFOR
loGrid.refresh()
CATCH TO loException WHEN loException.ErrorNo = 1683 && no index tag
with this name...ignore
IF _vfp.StartMode = 0 THEN
MESSAGEBOX(loException.Message,16,"Problem")
ENDIF
CATCH TO loException
MESSAGEBOX(loException.Message,16,"Problem")
SET STEP ON
ENDTRY
ENDIF && !EMPTY(lcOrder)
SELECT (lnOldArea) && restore previous work area
There's a couple form props you'll see referenced above which are
self-explanatory. This code basically allows me to create sorted
columns on the fly.
hth,
--Mike
On 2016-05-13 15:25, rafael copquin wrote:
In addition to what Peter says:
when you click on the column you want to, put this code
set order to ... in .....(the table or cursor)
this.parent.parent.refresh
Those two lines of code will do what you want. Of course, we are
talking of a grid here, not a browse
Rafael Copquin
On 13/05/2016 13:21, Peter Cushing wrote:
On 13/05/2016 16:44, Joe Yoder wrote:
I need to present information from several tables. I want to enable
the
user to click on a column header to control the order in which the
records
are displayed. At this point it does not need to be very polished so
a
simple browse with scrolling, column resizing and repositioning, with
control F find will be fine.
I do this with a grid on a form. I create a cursor in the init or
load and set that as the recordsource etc. then fill it with data and
index on the columns you want to be able to set order to. To change
the order just click on the column header and some code behind that
changes the index order. Grids are definitely more work than a browse
but you can do a lot more with them, like the column header click.
Peter
This communication is intended for the person or organisation to whom
it is addressed. The contents are confidential and may be protected in
law. Unauthorised use, copying or disclosure of any of it may be
unlawful. If you have received this message in error, please notify us
immediately by telephone or email.
www.whisperingsmith.com
Whispering Smith Ltd Head Office:61 Great Ducie Street, Manchester M3
1RR. Tel:0161 831 3700 Fax:0161 831 3715
London Office:17-19 Foley Street, London W1W 6DW Tel:0207 299 7960
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.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.