Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Bong Bungalan
  Where is Bong Bungalan?
 gensan
 Philippines
 Bong Bungalan
 Tags
Subject: RE: Adding Header.Click() event at runtime
Thread ID: 268547 Message ID: 268554 # Views: 49 # Ratings: 8
Version: Visual FoxPro 9 Category: Classes and Objects
Date: Tuesday, July 13, 2010 8:37:29 AM         
   


Hi Bong,

> One of it is adding a Sort Routine in the interactive SearchForm. if the user clicks on the Grid's Header whose Column's ControlSource is indexed and if not, it will do nothing. For you guys to understand better, below is the pseudo code of the class.
>

(As you know, just "for the records": you do not necessarily need to use Define Class syntax inside PRGs since designing "visual" classes in the visual Class Designer might be easier.)

> My questions are:
>
> 1. Do I need to add additional Object like 'Add Object loHeader as Header'? if so, which part of the code will I insert? or
> 2. I should have to have a procedure like
> 'Procedure grdSearch.columns(lnColNo).Header1.Click()? or
> 3. I need to use bindEvent (<--- I find it hard to understand yet) and add custom method to the class? if so, how?
>

You are exactly right about the different approaches: you can either replace the grid.Columns standard header at run time using doing some "For Each", "column.NewObject(...,'yourHeaderClass,...)".
That approach is the "traditional" one and there is nothing wrong with it.
The newer BindEvent() and .MemberClass/Library approaches were introduced in the most recent VFP versions. Both are working well too, and in your case it might be a matter of taste which one to use, in my opinion.

While a disadvantage of BindEvent() is that it can be quite difficult to maintain/debug, i.e. it is not always obvious while looking at code or inside the debugger whether a BindEvent() (or property_access()/_assign() for that matter) might have caused certain behavior, so that in many scenarios classical sub-classing might be preferable,
in your case, i.e. while dealing with an "unknown" number of "unknown" objects it can be very suitable, see sample pasted below.


hth
-Stefan

LOCAL oForm
oForm = CREATEOBJECT('TestForm')
oForm.Show(1)
RETURN

DEFINE CLASS TestForm as Form
	AutoCenter = .T.
	AllowOutput = .F.

	PROCEDURE Load
		CREATE CURSOR temp (test C(10), test2 C(10))
		INDEX on ASC(test2)%2 TAG test2
		INDEX on test TAG test

		LOCAL i
		FOR i = 1 TO 26
			INSERT INTO temp VALUES (CHR(i+64),CHR(90-i))
		ENDFOR
		GO TOP
	ENDPROC

	ADD OBJECT Grid1 as Grid WITH ;
		RecordSource = 'temp', ;
		ColumnCount = 2, ;
		AllowCellSelection = .F.
	PROCEDURE Grid1.Init()
	    Local oColumn
	    For Each oColumn in This.Columns
	    	BINDEVENT(oColumn.Header1,'Click', ;
	    		Thisform, 'SetOrder')
	    Next
	ENDPROC

	PROCEDURE SetOrder
		LOCAL aEventSource[1]
		AEVENTS(aEventSource,0)
		SET ORDER to ( ;
			GETWORDNUM(aEventSource[1].Parent.ControlSource,2,'.') )
		Thisform.Grid1.Refresh()
	ENDPROC
	PROCEDURE Grid1.AfterRowColChange(nColIndex)
		? RECNO('temp')
	ENDPROC 

ENDDEFINE


ENTIRE THREAD

Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 8:15:49 AM
RE: Adding Header.Click() event at runtime Posted by Bhushan Sahni @ 7/13/2010 8:20:56 AM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 8:33:49 AM
RE: Adding Header.Click() event at runtime Posted by Bhushan Sahni @ 7/13/2010 8:35:09 AM
RE: Adding Header.Click() event at runtime Posted by Stefan Wuebbe @ 7/13/2010 8:37:29 AM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 9:12:34 AM
RE: Adding Header.Click() event at runtime Posted by Stefan Wuebbe @ 7/13/2010 10:00:19 AM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 2:18:31 PM
RE: Adding Header.Click() event at runtime Posted by Stefan Wuebbe @ 7/13/2010 3:29:19 PM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 3:52:15 PM
RE: Adding Header.Click() event at runtime Posted by Stefan Wuebbe @ 7/13/2010 4:17:35 PM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 4:31:10 PM
RE: Adding Header.Click() event at runtime Posted by tushar @ 7/13/2010 4:23:10 PM
RE: Adding Header.Click() event at runtime Posted by Bong Bungalan @ 7/13/2010 4:37:24 PM
RE: Adding Header.Click() event at runtime Posted by tushar @ 7/13/2010 4:43:17 PM
RE: Adding Header.Click() event at runtime Posted by tushar @ 7/13/2010 8:46:25 AM