PRB: Pressing ENTER on a Check Box Runs Default Push Button

ID: Q125005

The information in this article applies to:

SYMPTOMS

If you press the ENTER key while the insertion point is positioned in a check box, code unrelated to the check box executes.

CAUSE

In the screen set, you have a push button defined as a default push button.

WORKAROUND

Use one of the following workarounds:

STATUS

This behavior is by design.

MORE INFORMATION

According to the FoxPro for Windows Help file:

A default Push Button is typically used to exit a data-entry screen, dialog, or routine and accept any changes made in the screen, dialog, or routine.

If a screen has a default Push Button defined, the code of the Valid or When clauses of that button is executed when the ENTER key is pressed while on a Check box. As a result, the screen may behave in an unanticipated way with no indication as to the source of the behavior. Code in the Valid clause of the Check Box is not executed.

To create a default Push Button, place a backslash and an exclamation point (\!) before the Push Button's prompt. The following example specifies the OK button as the default Push Button:

   STORE 1 TO mchoice
   @ 2,2 GET mchoice FUNCTION '*  \!OK;Cancel'
   READ

In FoxPro for Windows, the default button is identified by a thick black border around the button. The default button is automatically chosen when you press the ENTER key, CTRL+ENTER, or CTRL+W.

Also, according to the Help file:

The KEYCOMP setting determines the behavior of default Push Buttons in FoxPro for Windows in the following ways:

Steps to Reproduce Behavior

Create and run a program containing the following code:

   DEFINE WINDOW testwin ;
        AT 0.000, 0.000 ;
        SIZE 10.000,67.000 ;
        FONT "MS Sans Serif", 8 ;
        FLOAT ;
        NOCLOSE ;
        MINIMIZE ;
        SYSTEM

   MOVE WINDOW testwin CENTER

   ACTIVATE WINDOW testwin

   @ 2.800,12.400 GET getfield ;
        SIZE 1.000,16.000 ;
        DEFAULT " " ;
        FONT "MS Sans Serif", 8 ;
        PICTURE "@K"
   @ 2.900,33.500 GET cbox ;
        PICTURE "@*C check box" ;
        SIZE 1.300,14.500 ;
        DEFAULT 0 ;
        FONT "MS Sans Serif", 8 ;
        STYLE "BT"
   @ 6.500,19.500 GET button ;
     PICTURE "@*HN \!Quit" ;
     SIZE 1.700,7.500,0.750 ;
     DEFAULT 1 ;
     FONT "MS Sans Serif", 8 ;
     STYLE "B" ;
     VALID byebye()

   READ CYCLE
   RELEASE WINDOW testwin

   FUNCTION byebye     &&  Button VALID
   WAIT WINDOW "Quitting..."

Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a KBCategory: kbui kbprg kbprb KBSubcategory: FxotherGeneral

Last Reviewed: June 27, 1995