Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

want to detect esc key or enter key from inside a column in a grid 3

Status
Not open for further replies.

vj

Programmer
Nov 18, 2000
58
MU
hi everyone,

i have a grid with names ... as i scroll down through the names i want to make the grid invisible just when i press escape or enter keys ... is there a problem with the inkey() or lastkey() working from inside the girds ?

thankx
Vijay
 
inkey() is the wrong function overall as you actively use it to wait for a key at a certain position in code, how would you use that to wait for keys in a grid?
The lastkey() is ok, but you don't need it, when using the keypress event.

Use keypress of the textboxes within the grid, not keypress of the grid control itself. The grid is just the outer frame and record/deletion marks plus the grid lines. Users work within the grid column controls. They get the events (not only keypress, also interactivechange etc), not the grid control. The grid control is unimpartant for that matter.

The only other place you get all keypresses is the form.keypress, when you set form.keypreview=.t.

To have centralised code in the grid, you'd use BINDEVENTS() to bind all the keypress events of the columns controls to the grid.keypress and program your ENTER or ESC key behaviour there. Use the parameters passed in, not lastkey().

Bye, Olaf.
 
I agree. The Keypress is definitely way to go in this case. Your code will look something like this:

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl

IF INLIST(nKeyCode, 13, 27)
  this.Parent.Parent.Visible = .F.
ENDIF

I'm not sure about the user interface issues of making the grid invisible in the way you described, but no doubt you have a good reason for it.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
And don't forget Form.KeyPreview=.t. or the control will never get the keypress.
 
Adding a little background here... in a VFP grid, you're never in a column. You're always in a cell. OK, not quite. The cell holds some other object, by default a TextBox. That's what you're in. So, as others have said, use the KeyPress event of the textbox.

Craig Berntson
MCSD, Visual C# MVP,
 
Who said column? I said column controls, the controls within the columns. So by default it's a textbox, sure, and in the end we agree. But it can be anything added to the column, in rare cases using the dynamiccurrentcontrol it doesn't even need to be the currentcontrol.

You can loop all columns via FOR EACH loColumn IN THIS.Columns, then have a nested loop over all column controls: FOR EACH loControl IN loColumn.Objects. Within that inner loop check for loColumn having a Keypress event, and if it has, bind the grid keypress to it, then you redirect all keypress events to the central grid.keypress event.

Bye, Olaf.
 
hi every one,

thankx to everyone for all the info ... just have to check for nkeycode equal to 13 or 27 or any key one wishes to check against .. in keypress of the text control of the column inside the grid ... and also have to set the forms keypreview to .T. (this is what i was missing)

thankx alot
vijay
 
>have to set the forms keypreview to .T.

Only, if you want to process keys in the form.keypress event. The advantage is, you get every keypress from everywhere in the form, the disadvantage is, you don't know whether a key was pressed while the grid or one of it's inner controls is active.

It never harms to set keypreview=.t., as the specific control get's the keypress event, too.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top