ID: Q124779
2.60a WINDOWS
The information in this article applies to:
A combo box is a object into which you can enter data directly or select an item from a predefined drop-down list. FoxPro does not have a combo box option to choose when making a screen, but you can use the technique presented in this article to simulate a combo box in FoxPro.
The code in the VALID clause of the GET object will vary depending on where the information for the drop-down list comes from: arrays, a field from a table, or defining bars for the popup box. Use the following steps to make a combo box by using a popup with a predefined list:
1. Create a screen in FoxPro, and add a GET object to the screen, giving it
the variable name of COMBO. Make sure it is a character field.
2. In the VALID clause of the object COMBO, add the following code:
IF EMPTY(combo)
DEFINE POPUP combobox FROM 7,25 to 14,50
DEFINE BAR 1 OF combobox PROMPT 'Choice 1'
DEFINE BAR 2 OF combobox PROMPT 'Choice 2'
DEFINE BAR 3 OF combobox PROMPT 'Choice 3'
DEFINE BAR 4 OF combobox PROMPT 'Choice 4'
DEFINE BAR 5 OF combobox PROMPT 'Choice 5'
ON selection popup combobox DO getcombo WITH PROMPT()
ACTIVATE POPUP combobox
ENDIF
SHOW GETS
3. In the cleanup code of the screen, add the following code:
PROCEDURE getcombo
PARAMETER mprompt
combo=mprompt
KEYBOARD '{TAB}' && Moves you off of the popup after
&&pressing ENTER to select your choice.
4. Add a push button to the screen; call it EXIT. In the VALID clause,
put the code CLEAR READ.
After generating and running the screen, you will see that the object that
represents the combo box is blank. If information is not typed into the
object before the ENTER key is pressed, the code in the VALID clause of the
field is executed and the popup appears.
Adjust the coordinates in the DEFINE POPUP statement if you want the popup to overlay the get field exactly. The example code shows how to define bars for the popup. If you want information from a field to be listed in the popup, change the code as indicated below.
NOTE: This code uses the CUSTOMER.DBF file located in the TUTORIAL subdirectory of FoxPro.
In the VALID clause of the COMBO GET object, change the code to match this:
IF EMPTY(combo)
DEFINE POPUP combobox PROMPT FIELD cno FROM 6,29 TO 12,43
ON SELECTION POPUP combobox DO getcombo
ACTIVATE POPUP combobox
ENDIF
SHOW GETS
In the cleanup code, change the code to match this:
PROCEDURE getcombo
combo=<fieldname> && This is the fieldname that follows the PROMPT
&& FIELD clause in the DEFINE POPUP
KEYBOARD '{TAB}'
This revised code fills the popup with the information from all the records
in that table of that field. Again, to position the popup on the screen
where you want it, experiment with the numbers of the DEFINE POPUP
statement.
Additional reference words: FoxWin SBuilder 2.60a KBCategory: kbprb KBSubcategory: FxtoolSbuilder
Keywords : kbcode FxtoolSbuilder
Version : 2.60a
Platform : WINDOWS
Last Reviewed: May 22, 1998