Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox Property Confusion

Status
Not open for further replies.

IForgotAgain

Programmer
Sep 20, 2005
12
US
This is something that has been bothering me and I figure that now is as good a time as any to get things clarified.

When I use ComboBox's on a form, there continues to be some confusion as to which property I need to examine in order to determine the input visible on the form.

Value
Text
DisplayValue

The VFP7 Help file does not make it clear as to which property I should be getting data from.

I have been using the following, but I have to admit that it has been through trial-and-error, not through a knowledgeable choice.

Code:
* --- Used when initializing ComboBox to display a known value ---
* -------  Correct?? Or Not?  ------
ThisForm.cboMyCombo.Value = mcNewDisplay  

* --- Used when getting values from ComboBox ---
* --- Which One???  Sometimes one seems to work and sometimes the other ---
mcUserInput = ThisForm.cboMyCombo.Text
mcUserInput = ThisForm.cboMyCombo.DisplayValue
[\Code]

I am hoping that someone out there can explain this CLEARLY so that I can begin using the appropriate property from a position of knowledge, not luck.

Thanks,
I_Forgot_Again
 
Value is always the actual value of the combobox. Whether it's the same as DisplayValue depends on the BoundColumn and BoundTo.

The difference between Text and DisplayValue is formatting. Text is unformatted and is always character--exactly what the user typed. DisplayValue may be formatted based on the Format and InputMask properties.

A little more on Value from one of my books:

For combo and list boxes, things get interesting. Value can be either character or numeric. If it's character, it contains the actual text of the chosen item—as a character string. Even if the RowSource data is something other than character, when it's placed in a list or combo, it's converted to character there. If Value is numeric, it's the Index in the list or combo of the chosen item. In VFP 5 and later, you can put a numeric data item in Value (as a character string, of course) by setting the list or combo's BoundTo property to .T. This lets you show a description in the list while saving a numeric ID for the Value. In VFP 3, there's no way to use numeric data for the Value of a list or combo.

Tamar
 
Hello IforgotAgain.

Here is the relevant section from Chapter 5 of "1001 Things":

What is the difference between DisplayValue and Value?

Combo boxes are particularly powerful controls because they enable you to display descriptive text from a lookup table while binding the control to its associated key value. This is possible only because the combo box has these two properties. Understanding the role each of them plays can be confusing, to say the least.

DisplayValue is the descriptive text that is displayed in the textbox portion of the control. This is what you see when the combo box is "closed." The combo's DisplayValue always comes from the first column of its RowSource. On the other hand, the combo's Value comes from whichever column is specified as its BoundColumn. If the BoundColumn of the combo box is column one, its Value and DisplayValue are the same when the user picks an item from the list. When the control's BoundColumn is not column one, these two properties are not the same.

Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top