How to Store Numeric Values that Come from a Combo BoxID: Q139214 3.00 WINDOWS kbprg kbhowto The information in this article applies to:
SUMMARYWhen the ControlSource property of a combo box or list box evaluates to a numeric variable and the list box displays numeric data, the ControlSource stores the index number (position) in the list, not the data that is displayed. This article shows by example how to store the numeric value listed in a combo box in a numeric variable.
MORE INFORMATIONThe RowSource property of a combo box or list box specifies the source of the values; that is, it indicates where the data is coming from. The ControlSource property of a combo box specifies the data that is modified when a selection is made. It indicates where the data is going to. When a combo box is bound to a character variable, the expression displayed in the list is stored to the ControlSource. When the object is bound to a numeric variable, the index order of the expression is stored to the ControlSource. For example, say the list displays the following elements:
If the number 30 is selected when the data is bound to a numeric variable,
the variable stored in the ControlSource property will evaluate to 3,
because 30 is the third element in the list. If the data originates from a
table, this index can correspond to a record number.
When a combo box or a list box is not bound to any data, ControlSource is empty. The Value property stores the character string that is currently selected. Using the previous example, the Value property is equal to 30 if the list box is not bound to data. The Visual FoxPro Help file indicates that once the ControlSource property is set to a field or variable, the Value property always has the same data value and the same data type as the variable or field to which the ControlSource property is set. To store the numeric selection of a combo box to a numeric variable, you can assign the value of the combo box to the variable in the Interactive Change event handler. This assumes that the object is not bound to data. The following step-by-step example illustrates this procedure.
Step-by-Step Example1. Create a new form. 2. Right-click the form, and then click Data Environment. 3. In the Data Environment, open the Orders table located in the 4. Select the form, and place a combo box on the form.
5. Change the following properties for the combo box:
6. Create a new property for the form, and name it nSelectData.
7. In the InteractiveChange event handler for Combo1, type:
8. Save and run the form. To verify the value of the nSelectData variable,
Additional reference words: 3.00 combobox listbox
KBCategory: kbprg kbhowto
KBSubcategory: FxprgGeneral
|
Last Reviewed: November 15, 1995 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |