Microsoft KB Archive/138918

= How to Make a Modal List Box on a Form =

Article ID: 138918

Article Last Modified on 2/11/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q138918



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
 Create a new class based on a Container. Name it MyList, and store it in Mylib. Set the following Properties for the MyList container:

BackStyle = 0-Transparent

BorderWidth = 0

Height = 195

Width = 165

 Add a new Property to the class, and call it Flag. 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

  In the GotFocus event of MyList, enter the following code: This.Flag = .F.                         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   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. </li>  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. </li> Save the class, and then close the Class Designer.</li> Create a new Form.</li> 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.</li></ol>

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 query words: VFoxWin

Keywords: KB138918

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.