Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. sponsors. rss.
 From: Ammar Hadi
  Where is Ammar Hadi?
 Al-Samawah
 Iraq
 Ammar Hadi
 To: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 Tags
Subject: RE: Sorting the Grid by Header Clicking
Thread ID: 232107 Message ID: 232135 # Views: 25 # Ratings: 0
Version: Visual FoxPro 9 SP2 Category: Grids
Date: Friday, June 19, 2009 10:52:32 PM         
   


> > Hi my friends.
> > In a recent thread about sorting a grid by header clicks, I posted a way I used to do that.
> > I improved it a little bit and posted a sample form in my blog with some explanation of the procedure.
> >
> > It may be useful to some of you.
> >
> > My Foxite Weblog
> >
> > sample form to download:
> > http://www.foxite.com/uploads/5c545b64-b731-4c6f-bae4-4e20ed0c6c5b.rar
> >
> > sample form picutre:
> >
> >
> >
> > Best regards.
> >
> > Ammar Hadi ................IRAQ
> >
> > ---------------
> > I I I really love foxite
> > ___________________________
>
> Hi Ammar and thanks for sharing your code.
> i just have one remark: you repeat pratically the same code in all click event of the headers (safe the numero of index).I recommend you to work with bindevent in any click on any header,if concerned by the sorting.try this code:
>
> in form.init add
>
> 		for i=1 to this.grdsort.columncount
> 		if inlist(i,1,2,3)  &&choice only the column to sort asc/descending-grid can have any columnCount
> 		aa="this.grdsort.column"+trans(i)+".header1"
> 		bindevent(&aa,"click",thisform,'ybind')
> 		endi
> 		endfor
> 

> and create a method "ybind" with this code
>
> 		x=sys(1270)
> 		n=val(right(allt(x.name),1))
> 
> 		SELECT tempStudents
> 		IF VAL(SYS(21))<>n  && current index number
> 		  SET ORDER TO n IN tempStudents
> 		ELSE
> 		  IF DESCENDING(n,"tempStudents")
> 		    SET ORDER TO n IN tempStudents ASCENDING
> 
> 		  ELSE
> 		    SET ORDER TO n IN tempStudents DESCENDING
> 
> 		  ENDIF
> 		ENDIF
> 		THIS.grdsort.SETALL("picture","","HEADER")
> 
> 		y="this.grdsort."+allt(x.name)+".header1.picture"
> 		&y=IIF(DESCENDING(n,"tempStudents"), THISFORM.picdesc, THISFORM.picace) && the sorting icon
> 
> 		GO TOP IN tempStudents
> 		THIS.grdsort.REFRESH
> 		THIS.grdsort.SETFOCUS
> 

> with this you can generalize to any grid with any columncount.
> I see this remarkable opportunity in Listview controls and even in subclass of grids.
>
>
> Dont rate please.its only for the pleasure to help.Give me only a feed back.
> Yousfi Benameur

Thanks for your note Yousfi.
I thought about using 1 method in the form to control it, but I admit that bindevent() flied away from my head at that moment. Bindevent() is definitely a more professional choice.

Thanks for sharing your ideas too.

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

My Foxite Weblog

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



COMPLETE THREAD
Sorting the Grid by Header Clicking Posted by Ammar Hadi @ 6/19/2009 8:21:12 PM
RE: Sorting the Grid by Header Clicking Posted by Yousfi Benameur @ 6/19/2009 9:59:58 PM
RE: Sorting the Grid by Header Clicking Posted by Ammar Hadi @ 6/19/2009 10:52:32 PM