Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Keytrapping in a Grid
Message
De
17/07/2002 12:41:12
 
 
À
17/07/2002 10:27:46
Carmen Gassi
Perseus Software Systems
Oakville, Ontario, Canada
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00679588
Message ID:
00679667
Vues:
28
This message has been marked as the solution to the initial question of the thread.
>I am currently working with a grid where a user would like to do quick data entry, validate the data from existing tables and add new records while in the grid. Since KEYPRESS event doesn't function withing a grid ( at least I haven't been able to get to work ), if I want to trap for say the INS key being pressed, is it best to do it in the Beforerowcolchange method using LASTKEY() ?
>
>Thanks to all
>Regards,
>Carmen


Carmen,

You can trap each keystroke in any control by setting the form.KeyPreview = TRUE
Having done that the form.KeyPress will fire for each key that is pressed
In the form.KeyPress you can find out what control is active and what its controlsource is

It takes a bit more of the cpu and I always use this if it is for controls in a grid
There are a lot of CASEs in, but it then it is easy to add some code for another keystroke
Example
&& Form.Keypress
LPARAMETERS nkeycode,nshiftaltctrl

local ac, cs
do case
case (nShiftAltCtrl == 0)
    do case
    case inlist(nKeyCode, 22)	&&Ins
       ac = thisform.GetActiveControl()
       do case
       case !isNull(ac)
           do case
           case ac.BaseClass == 'Textbox'  && and assuming it's in a grid
               cs = ac.ControlSource
               do case
               case upper(cs) == 'Table1.CustID'
                   NODEFAULT
                   append blank in (ac.Parent.Parent.RecordSource)
                   =ac.Parent.Parent.Refresh()
               endcase
           endcase
       endcase
    endcase
endcase
&& form.GetActiveControl
lparameters	DoNotGoDownIfGrid

local	_ActiveControl, _ActiveColumn, i, x

if( type('thisform.ActiveControl') == T_UNDEFINED )
	return .Null.
else
	_ActiveControl = thisform.ActiveControl
endif

if( !(type('_ActiveControl') == T_OBJECT ) )
	suspend
endif

if( !DoNotGoDownIfGrid and (Proper(_ActiveControl.BaseClass) == 'Grid') )
	_ActiveColumn = _ActiveControl.ActiveColumn
	
	if( !empty(_ActiveColumn) )
		for i = 1 to _ActiveControl.ColumnCount
				x = _ActiveControl.Columns[i]
			if( x.ColumnOrder == _ActiveColumn )
				exit
			endif
		endfor
		for i = 1 to x.ControlCount
			if ( x.Controls[i].Name == x.CurrentControl )
				_ActiveControl	= x.Controls[i]
				exit
			endif
		endfor
	endif
endif

return _ActiveControl
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform