Reputation: 135
I have a grid with 2 columns like Name, Address. Clicking on a name will display person picture, for example. I like to do that just pressing Enter in the higligted text box in column1. Problem is that pressing Enter shifts focus to Column 2 and my grid scrolls horizontally. The only way to achive what I want is to turn Enabled to false on Column2, but doing that I cannot do eventual edits in address columns. Could anyone (still remembering VFP!) point me in the right direction?
Upvotes: 1
Views: 1343
Reputation: 48139
Open your form that has the grid. Bring up your properties window, click on the grid. On the combo at the top of the properties window, expand that to expose the Column1, Header1, Text1, etc of the columns in the grid. Select the "Text1" control if this is the one you want to have the enter key NOT advance...
Double-click on the "KeyPress Event" and it will bring up a default snippet. Change to the following...
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = 13
NODEFAULT
RETURN
ENDIF
The "nKeyCode" is the value of the keypress... ex: 13 = Enter key. So, if the incoming keypress is that of 13, DO NOT do the normal behavior. Issuing a "NODEFAULT" prevents the normal focus change as you are encountering.
Upvotes: 1