Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort records on a grid by the columns...

Status
Not open for further replies.

shenlon

Programmer
Jul 9, 2003
47
0
0
US
I have a grid of all the inventory I have in stock (cars in this case) and I would like to be able to click the top of a column (Year, Make, Model, etc.) and then have the grid resorted on ascending/descending value for that specific column. I'm sure this must be a fairly basic thing to do, but I can't seem to figure it out for VFP 6.0. Thanksin advance to all who can help.
 
Hi Shenlon,

You are right ... this is straightforward.

First, make sure you have an index for each of the fields that you want to sort on. Then, in the Click event of each of the column headers, put a SET ORDER TO command for the relevant index.

For example, if the first column is Year and the index is called Year, just do SET ORDER TO YEAR in Column1's header.

Be sure to put the code in the header within the column, not the column itself. You might also need to do a THISFORM.Refesh (but I don't think so).

Mike


Mike Lewis
Edinburgh, Scotland
 
Add a SET ORDER TO .... in the Click event of the header.

Here's what I have done. First, a Form method named 'CaptionReset'. In the CaptionReset method:
Code:
*... set all headers to plain text
WITH Thisform.pageframe1.pgBrowse.grdComputer
  FOR zzz = 1 TO .ColumnCount
     STORE 'Column' + Alltrim(Str(zzz)) TO cCol
     IF '*' $ .&cCol..header1.Caption
        .&cCol..header1.Caption = ;
           Left(.&cCol..header1.Caption, At('(', .&cCol..header1.Caption) -1)
     ENDIF 
  NEXT 
ENDWITH

Then in the header click event:
Code:
SET ORDER to company 
ThisForm.CaptionReset()
DO CASE 
   CASE '-' $ This.Caption 
      SET ORDER to company ASCENDING   
      This.Caption = This.Caption + '(+)'
   
   CASE '+' $ This.Caption 
      SET ORDER to company DESCENDING
      This.Caption = This.Caption + '(-)'
 
   OTHERWISE   &&... not previously set
      SET ORDER to company ASCENDING   
      This.Caption = This.Caption + '(+)'

ENDIF


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top