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
- 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.
- 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.
- Save the class, and then close the Class Designer.
- Create a new Form.
- 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.
|