Selecting Items from List Box Using Object's WHEN Clause

Last reviewed: April 30, 1996
Article ID: Q119886
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5x, 2.6, 2.6a
  • Microsoft FoxPro for Macintosh, versions 2.5x

SUMMARY

In FoxPro, the WHEN clause of an object is triggered any time an item in a list box is selected. In the following example, a user can select an item from a list box using a single mouse click instead of double-clicking the item as would be required if only the VALID clause were used.

MORE INFORMATION

  1. USE the CUSTOMER table found in the <FoxPro_directory>\TUTORIAL subdirectory.

  2. Create a new screen.

  3. In the Setup code for the screen, add the following command:

          SELECT COMPANY FROM CUSTOMER INTO ARRAY TEST
    

  4. Create a GET field. In the Input box, type "X" (without the quotation marks).

  5. Place a list box on the screen. In the List Items box, select the From Array option and type "TEST" (without the quotation marks) for the array name. In the box for the list box variable, type "LISTVAL" (without the quotation marks) for the variable name.

  6. In the WHEN clause of the list box, enter the following code:

          X=TEST(LISTVAL)         && Assign the GET field variable a value.
          SHOW GET X              && Update screen.
    
    

  7. Generate the screen and run it.

The GET field will be automatically filled with the first value in the list box. If the user clicks (or double-clicks) any item in the list box, the GET field will be updated. Additionally, if the user presses TAB to move to the list box, the currently selected value in the list box will update the contents of the GET field.


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.50c 2.60
2.60a
listbox
KBCategory: kbprg
KBSubcategory: FxprgGeneral


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.