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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exit from a grid

Status
Not open for further replies.

Roobert

Programmer
Sep 29, 2022
3
RO
Hi. I have a customer that wants to use Dos Fox commands worming into a grid (ctrl+n; ctrl+t; ctrl+w). I stack to exit from the grid. He wants to use CTRL+W instead to push a save button from the form. But from grid I cannot use "ON KEY LABEL CTRL+W thisform.save.clic" (error thisform can only be used within a method)
Does anyone have any suggestions?
 
First of all standard hotkey for saving is CTRL+S, I strongly recommend notusing CTRL+W for that.

Access keys are usually used for that, but the are ALT+something combinations not CTRL.

To use CTRL combinations I'd use a context aka popup menu in which you define a save item. These menuhotkeys also work, if you don'T show/activate the menu, so there you have a central entity for defining hotkeys.

But there's another standard mechanism for buttons, the default and cancel buttons, buttons with their default or cancel property set to .T. can then also be triggered by ESC (cancel) and ENTER (default).

Well and by windows design a default button usually is the OK button that saves changes/settings made and closes a form, so it's very much usable for the save button. From anywhere, no matter what has the current control. You could argue for ENTER neither being CTRL+S nor CTRL+W, as by your original plan and also ENTER being necessary when you SET CONFIRM ON, just to signal end of input. But you also have tab for, well, tabbing to the next control. And as the help describes it the only other problem of using ENTER within a editbox is not your problem as you say the user is acting within a grid. Even if you make one grid column an editbox, there's CTRL+ENTER.

A menu item also can't use THISFORM, but the code that executes can be defined on the fly with ON BAR and can use an object variable referencing the form, besides you have _Screen.Activeform Just be warned that ON KEY LABEL is global, that it could be triggered if no form is active and then activeform is NULL and using it triggers an error. So first check whether _Screen.activeform actually is not null, if you use it, which makes it incompatible to use in a simple one-liner code, even when you think of using IIF or EXECSCRIPT. You better call something, but then for encapsulation reasons it should be a form method and you recurse into the problem of not being able to use THISFORM or rely on ACTIVEFORM.

You could try to define a general purpose save method in your application class (usually active and globally visible as goApp) and call that, which in turn could see whether _screen.activeform is valid and then use that to call the form specific save method. That would work, though I still don't like using ON KEY LABEL for something that should have a limited local scope only, even when you consider CTRL+S to be a general hotkey anyway so it deserves being a goApp "event".





Chriss
 
Chris said:
A menu item also can't use THISFORM,
Hi Chris,

As you point out, this will NOT work:

Code:
DEFINE POPUP Reports SHORTCUT FROM MROW(), MCOL()
DEFINE BAR 1 OF Reports PROMPT 'Client List' INVERT
ON SELECTION BAR 1 OF Reports THISFORM.RpClients()
ACTIVATE POPUP Reports

However, I found (for some strange reason) this WILL work:

Code:
WITH THISFORM
 DEFINE POPUP Reports SHORTCUT FROM MROW(), MCOL()
 DEFINE BAR 1 OF Reports PROMPT 'Client List' INVERT
 ON SELECTION BAR 1 OF Reports .RpClients()
 ACTIVATE POPUP Reports
ENDWITH

Steve
 
:)
Tanks from response, but you got away from my problem.
I have a form with text boxes, buttons (save) and a grid.
Grid, normaly, is the last object used. Here I add several lines. The user do not want to use mouse to push save button. Wants (like in DOS) to do CTRL+W (currently use a old soft with this commands - you now ... DOS FOX programs works 99% only from keyboard).
 
Roobert,

Have you considered using the form's KeyPress event?

Code:
LPARAMETERS nKeyCode, nShiftAltCtrl
IF nKeyCode = 23
  * CTRL+W
  THISFORM.cmdSave.Click
ENDIF

You would also need to set the form's KeyPreview Tto .T.

That said, I agree with Chris that you should be using CTRL+S rather than CTRL+W, in which case the code to trap would be 19.

Also, rather than calling the button's Click event, it would be better to create a custom Save method, and to call that method from both the Save button and the KeyPress.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Roobert, I don't know what you interpret into my answer, but it's all about hotkeys.

Also the paragraph about the default and cancel property of buttons, as they activate the default keys for using them to be ENTER and ESC. While not CTRL+W, those are KEYS.

And the menu solution also is about hotkeys for the menu items. I don't intend to even show the menu, even less so suggest the user has to operate the menu with the mouse. Don't you know that you can define a hotkey combination with ALT or CTRL for any menu item? And it is indeed the general solution in VFP to have a shortcut aka context aka popup menu with the CUT/PASTE/SAVE menu items and the usual Windows hotkeys for them, including CTRL+S for saving.

You can also choose CTRL+W, if your customer insists on it, but it's surely not a Windows standard.

Please reconsider my answer in that light and if you still don't understand what I'm aiming for, please ask what I mean and don't state I misundertood your problem. That's not the case. I think you miss the point of either using the menu as a vehicle for defining hotkey combinations for actions and instead only think of the visual menu operated by mouse clicks and you may be deaf about the point of standards and supporting them, like the cancel and default buttons of forms. I may ask back, if I misread you have a save button defined. You do, don't you? It's really just setting it's default property to .T. and this button will react to ENTER key, not only when it has focus. Also when the focus is in the grid.

Chriss
 
It works with form's KeyPress event. Very easy :)
I had found a solution. I had sent it to an outside prg, but with condition to close de form at the end.
The problem with my solution would be if I have invalidations before saving and need to stay in form for corrections/completions.
Thanks very much.

PS: related to use CTRL+S ... if the client were not so rigid, he would be open to using the save button. We are in the era of visual programs :)
 
Okay, the Keypress is a simple solution, I agree.

Roobert said:
if the client were not so rigid, he would be open to using the save button

Didn't you say you have a save button? You said:

Roobert said:
CTRL+W instead to push a save button from the form.

I see, I interpreted this to be a save button that your customer wants to be usable with CTRL+W, too, not only by clicking it. But there is no button.


Chriss
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top