Presumably you already have an index tag on the relevant field.
You will also need a custom propery of the grid to hold the current direction. Let's call this property lAscending.
When you instantiate the grid, set the table's index order to ascending:
Code:
SELECT TheTable
SET ORDER TO TheTag ASCENDING
this.lAscending = .T.
Then, in the click event of the column's header, set the order accordingly:
Code:
SELECT TheTable
lcDirection = IIF(this.lAscending, "ASCENDING", "DESCENDING")
SET ORDER TO TheTag &lcDirection
this.lAscending = NOT this.lAscending
To visually show the current direction, create two small icons: one to resemble an upward-pointing arrow and one for downward-pointing. Let's call these Up.bmp and Down.bmp respectively. When you instantiate the grid, set the header's picture property to point to Up.bmp. Then, in the header's click event, toggle the picture property. So the whole code for the header's click will look something like this:
Code:
SELECT TheTable
lcDirection = IIF(this.lAscending, "ASCENDING", "DESCENDING")
lcPic = IIF(this.lAscending, "up.bmp", "down.bmp")
SET ORDER TO TheTag &lcDirection
this.column1.header1.picture = lcPic
this.lAscending = NOT this.lAscending
Finally, you will need to set focus to the grid to make the changes visible:
Do
not refresh the grid at this point. Setting the focus is sufficient and is faster. Also, if you refresh, you will lose the current highlight.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads