How to Make a Modal List Box on a Form

Last reviewed: October 31, 1995
Article ID: Q138918
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

When doing data entry there are times when you want the user to make a selection before moving on. This article shows how to make a list box that the user cannot leave until they make a selection.

MORE INFORMATION

If you are not familiar with creating classes or using the Form Designer and the different controls please see Chapters 9 - 11 in the Developer's Guide.

Steps to Make a Modal List Box

  1. Create a new class based on a Container. Name it MyList, and store it in Mylib.

  2. Set the following Properties for the MyList container:

    BackStyle = 0-Transparent BorderWidth = 0 Height = 195 Width = 165

  3. Add a new Property to the class, and call it Flag.

  4. Add a list box to the container, and set the following properties for the list box:

    Height = 190 Left = 3 Top = 3 Width = 160 RowSourceType = 1-Value RowSource = One,Two,Three

  5. In the GotFocus event of MyList, enter the following code:

    This.Flag = .F.

  6. In the LostFocus event of MyList, enter the following code:

    IF !This.Flag

          This.List1.SetFocus
    
    ENDIF &&Returns focus to the list if no selection is made

  7. In the Click event of List1, enter the following code:

    IF !This.Parent.Flag

          This.Parent.Flag = .T.
    
    ENDIF &&Lets them leave if they click to make a selection.

  8. In the Valid event of List1, enter the following code:

    IF !This.Parent.Flag

          This.Parent.Flag = .T.
    
    ENDIF &&Lets them leave if they made a selection with the keyboard.

  9. Save the class, and then close the Class Designer.

  10. Create a new Form.

  11. Place a text box on the form, and then place the MyList container class

        on the form. Then place a second text box on the form. Save the Form
        and then run it.
    

If you press the TAB key to move into the list box, you will not be able to press the TAB key to move back out unless you pick an item from the list using the mouse or keyboard.


Additional reference words: 3.00 VFoxWin
KBCategory: kbtool kbhowto kbcode
KBSubcategory: FxtoolFormdes


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: October 31, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.