Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ammar Hadi
  Where is Ammar Hadi?
 Al-Samawah
 Iraq
 Ammar Hadi
 To: Lylanie Tradio
  Where is Lylanie Tradio?
 Cebu
 Philippines
 Lylanie Tradio
 Tags
Subject: RE: Sort
Thread ID: 231913 Message ID: 231960 # Views: 2 # Ratings: 2
Version: Visual FoxPro 9 Category: General VFP Topics
Date: Thursday, June 18, 2009 10:40:33 AM         
   


> hello everyone!
>
> I really can't figure it out. I have this Grid and it has 18 columns and i have a button below the grid (Sort Active Column Button). i have tried every code my instructor gave me and i even make my own but it doesn't help. can any one please help me out of this one?
> I want to arrange in order based on what the user want to view in order.. like the memberid column, or the member name column, or even the area column... but how can i make it without having 18 buttons and use one instead...

Hi Lylanie,

See this picture, it from one of my applications, when the user click any header he will sort the grid on that column. No only that (a bonus for you :-)), when the user clicks it again, the grid will be sorted alternatively Ascending/descending:



To do that, you should have 2 icons in your project, one for descending (a small arrow downward) and the other for ascending (small arrow upward). At design time add the appropriate icon to the appropriate header(picture property) so that the correct sorting type on the correct index is reflected when you first show the form.

The cursor that is the source of the grid should be indexed on all the fields you want to sort according (by using INDEX ON ... ). For the code I will show you to work, when you define indexes start in the same order of columns that the grid start with, so that the first INDEX ON code will create index on the first field column. This is because (it is easy for me) I will use index numbers to deal with sorting. Then you set the order to the index you put the picture in its column header. This way you can Just copy paste the code you put in column header1 click to all other headers and just change the index number in the code to reflect the underlying field/column to sort on.

the code of the first header click event will be like this:

** the click event of header one (item names column)
* sort on.Item name (index 1)
LOCAL lcSortIcon
lcSortIcon=""

* Change order
IF DESCENDING(1,"tempItems")
 SET ORDER TO 1 IN tempItems ASCENDING
 lcSortIcon="sortascending.ico" && the name of my ascending arrow icon

ELSE
 SET ORDER TO 1 IN tempItems DESCENDING
 lcSortIcon="sortdescending.ico"

ENDIF

* the sort icon
THIS.PARENT.PARENT.SETALL("picture","","HEADER")
THIS.PICTURE=lcSortIcon

GO TOP IN tempItems
THIS.PARENT.PARENT.REFRESH
THIS.PARENT.SETFOCUS


In the header of column2, just change the three ones in the code to 2 and so on.

Hope this helps.

Ammar Hadi ................IRAQ

My Foxite Weblog

---------------
I I I really love foxite
___________________________

ENTIRE THREAD

Sort Posted by Lylanie Tradio @ 6/18/2009 4:55:44 AM
RE: Sort Posted by Erik Gomez @ 6/18/2009 5:10:57 AM
RE: Sort Posted by Lylanie Tradio @ 6/18/2009 5:37:48 AM
RE: Sort Posted by Erik Gomez @ 6/18/2009 6:04:27 AM
RE: Sort Posted by Lylanie Tradio @ 6/19/2009 3:02:37 AM
RE: Sort Posted by Erik Gomez @ 6/19/2009 5:13:24 AM
RE: Sort Posted by Anders Altberg @ 6/18/2009 12:13:04 PM
RE: Sort Posted by Anders Altberg @ 6/18/2009 4:28:35 PM
RE: Sort Posted by Ammar Hadi @ 6/18/2009 10:40:33 AM
RE: Sort Posted by Lylanie Tradio @ 6/19/2009 2:47:58 AM
RE: Sort Posted by Ammar Hadi @ 6/19/2009 7:03:35 AM
RE: Sort Posted by Lylanie Tradio @ 6/20/2009 11:00:30 AM
RE: Sort Posted by Ammar Hadi @ 6/20/2009 11:16:36 AM
RE: Sort Posted by Lylanie Tradio @ 6/20/2009 11:24:40 AM
RE: Sort Posted by Ammar Hadi @ 6/20/2009 11:27:31 AM
RE: Sort Posted by Anders Altberg @ 6/20/2009 12:09:35 PM
RE: Sort Posted by Marcia Akins @ 6/20/2009 3:48:25 PM
RE: Sort Posted by Anders Altberg @ 6/20/2009 3:56:16 PM