Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bindevent and Grid Columns
Message
From
28/05/2010 07:03:56
 
 
To
27/05/2010 17:49:20
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01466311
Message ID:
01466357
Views:
60
>I inherited a custom grid class. The definition of the grid shows a ColumnCount of 30. Three methods of EACH column in the grid have code in them.
>
>
>The MouseDown code for the Header of each column is
>
>LPARAMETERS nButton, nShift, nXCoord, nYCoord
>This.Parent.Parent.origcolnum = this.Parent.ColumnOrder
>
>The Click code for the Header of each column is
>
>IF this.Parent.Parent.origcolnum = this.Parent.ColumnOrder
>	this.Parent.parent.SortGrid(this.Parent)  
>ENDIF
>
>The DblClick code for the TextBox inside each column is
>
>this.Parent.Parent.filtercolumn=this
>this.parent.parent.DblClick()
>
>We've run into a situation where the ColumnCount for the grid needs to expand beyond 30 columns. Our "solution" is to expand the numbe of columns (to 50) and put this code into each new column's header/text box. This solution works and is therefore, by our definition, acceptable and has been implemented.
>
>OTOH, it seems to me that there should be a better solution by taking all this code out of the column header and text box and somehow using BINDEVENT() to get everything working. I don't have enough familiarity with BINDEVENT to do this and my (admittedly meager) efforts have been fruitless.
>
>Could somebody please provide some guidance on
>
>1. Is BINDEVENT a reasonable way of attaching code to the header/textbox of each column in the grid
>
>2. Coding technique for actually getting it done
>
>3. If the form reduces ColumnCount and later expands it, will all the columns still be "bound"
>
>4. If not is there an _ASSIGN method (or something else that doesn't have to be coded in the application) for ColumnCount where I can rebind all the columns?
>
>I hope this is comprehensible.........
>
>Thanks to all.............Rich

(1) Yes

(2) see below

(3) Reduce: yes, Expand: no, you'll have to run a method or (4) you can BindEvent to columnCount

Note that after grid init(), you'll have to call this method once
&& Form method - eg init
=m.this.GridColumnCountChanged()

=BindEvent(m.this.Grid1, 'ColumnCount', m.this, 'GridColumnCountChanged', 1)
Code of 'GridColumnCountChanged'
Go through columns - if 'TheColumnBinder' is not in, add it
with m.this.Grid1

	local i
	
	for i = 1 to .ColumnCount
		with .Columns[m.i]
			
			do case
			case !Inlist(vartype(.TheColumnBinder), T_UNDEFINED)
			
			case !.AddObject('TheColumnBinder', 'TheColumnBinder')
				assert .f.
			
			endcase
		endwith
	endfor
			

endwith
(2) There are a number of possibilities

The easiest - imo - is to add an object to each column.
When the column gets destroyed, the object also gets destroyed and can Unbind the events

When the object is added to a column, it binds the events
&& gridBinder
*===============================================================================
#include	"FoxPro.h"

#define	TRUE	.T.
#define	FALSE	.F.
*===============================================================================
#define TRACE_HERE	TRUE

#if TRACE_HERE
#	define	_SHOW	do _DebugOut with program()	
#else
#	define	_SHOW	*
#endif

*===============================================================================
#define PARAMETERLIST_04	p01, p02, p03, p04
#define PARAMETERLIST_08	PARAMETERLIST_04, p05, p06, p07, p08
#define PARAMETERLIST_12	PARAMETERLIST_08, p09, p10, p11, p12
#define PARAMETERLIST_16	PARAMETERLIST_12, p13, p14, p15, p16
#define PARAMETERLIST_20	PARAMETERLIST_16, p17, p18, p19, p20
#define PARAMETERLIST_24	PARAMETERLIST_20, p21, p22, p23, p24
*===============================================================================
*_______________________________________________________________________________
function IsObject(obj, BaseClassName)
	
	if( pcount() == 1)
		return inlist(vartype(m.obj), T_OBJECT)
	endif
	
	return 		inlist(vartype(m.obj), T_OBJECT) ;
			and	pemstatus(m.obj, 'BaseClass', 5) ;
			and	( proper(m.obj.BaseClass) == proper(m.BaseClassName) )
		

endfunc
*_______________________________________________________________________________
function	_DebugOut(prog_name,PARAMETERLIST_24)

		
	local	s, i
	p	=	pcount()

	s = ''
	for i = 2 to pcount()
		s = s + ',' + transf(eval('m.p' + padl(m.i-1, 2, '0')))
	endfor

	s = Proper(m.prog_name) + '(' + substr(m.s, 2)  + ')'
	
	acti screen
	? datetime(), ' ', m.s

endfunc
*_______________________________________________________________________________

*===============================================================================
*===============================================================================
*===============================================================================
define class TheColumnBinder as custom

*_______________________________________________________________________________
protected function Init()
	
	local success
	success = true
	
	do case
	case !m.success
	
	case !DoDefault()
		assert false
		success = false
	
	case !inlist(type('m.this.Parent'), T_OBJECT)
		assert false
		success = false
	
	case !IsObject(m.this.Parent, 'Column')
		assert false
		success = false
	
	case !inlist(type('m.this.Parent.Parent'), T_OBJECT)
		assert false
		success = false
	
	case !IsObject(m.this.Parent.Parent, 'Grid')
		assert false
		success = false
		
		
	case !m.this.BindEvents()
		assert false
		success = false
		
	endcase
	
	return m.success

endfunc
*_______________________________________________________________________________
#if false
	Unbind all events where we are involved
#endif
protected function Destroy()

	_SHOW, m.this.Name
	
	try
		=UnbindEvents(m.this)
	
	catch
	
	endtry

	
endfunc
*_______________________________________________________________________________
protected function BindEvents()

	
	local success
	success = true
	
	do case
	case !m.success
	
	otherwise
		with m.this.Parent && Column
			local i, obj
			
			for i = 1 to .ControlCount
				obj = .Controls(m.i)
				
				do case
				case isObject(m.obj, 'Header')
					=BindEvent(m.obj, 'MouseDown', m.this, 'HeaderMouseDown', 1)
					=BindEvent(m.obj, 'Click', m.this, 'HeaderClick', 1)
					
				
				case IsObject(m.obj, 'Textbox')
					=BindEvent(m.obj, 'DblClick', m.this, 'TextboxDblClick', 1)
				
				endcase
			endfor
		endwith
	
	
	endcase
	
	return m.success
	
endfunc
*_______________________________________________________________________________
protected function HeaderMouseDown(nButton, nShift, nXCoord, nYCoord)
	
	_Show, m.this.Parent.Name
	
	=AddProperty(m.this.Parent.Parent, 'origcolnum', m.this.Parent.ColumnOrder)

endfunc	
*_______________________________________________________________________________
protected function HeaderClick()
	
	_Show, m.this.Parent.Name

#if false
  I do not see why you test : IF this.Parent.Parent.origcolnum = this.Parent.ColumnOrder
imo, the MouseDown sets origcolnum.  And since a Click always follows a MouseDown, I think that the test is not necessary
Still, I've added the test
#endif	
	do case
	case !inlist(vartype(m.this.Parent.Parent.origcolnum), T_NUMERIC)
	
	case (m.this.Parent.Parent.origcolnum <> m.this.Parent.ColumnOrder)
	
	otherwise
			=m.this.Parent.parent.SortGrid(this.Parent)  
	
	endcase


endfunc	
*_______________________________________________________________________________
protected function TextboxDblClick()
	
	local aa[1]
	
	if( aEvents(aa, 0) == 3 )
		_SHOW
		=AddProperty(m.this.Parent.Parent, 'filtercolumn', m.aa[1])
		=m.this.parent.parent.DblClick()
		=AddProperty(m.this.Parent.Parent, 'filtercolumn', null)
	
	endif

endfunc
*_______________________________________________________________________________
enddefine

*===============================================================================
*===============================================================================
*===============================================================================
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform