>>>I wonder if there is a way to use a combobox that also allows free text entry? The list has different values from an array, but if I enter a text that is not found in the list it blanks out on Lostfocus.
>>
>>Combobox
allows free text entry, that's the idea behind the control.
>>
>>Non-listed values are stored in the .DisplayValue property, not in .Value.
>>
>
>That might be the problem, because I have a controlsource set and that means on Lostfocus it would try to update the underlying value which is empty. So I could write a wrapper control that binds the controlsource to the displayvalue instead, since the value is anyway only a text in my case.
Yes, Christian, you could do that. Just remember that you can trap the situation where user inserted something not part of the list by .Value being empty, and .DisplayValue being not empty.
This is a simple way of dealing with this, while the combobox is bound to a control source. As soon as the user inserts a new value, it becomes part of the list. Hence, its value can now set the control's .Value property, which, in turn, will populate the control source.
CREATE CURSOR TestData (Choice Char(10))
INSERT INTO TestData VALUES ('One')
LOCAL Test AS FormWithACombobox
m.Test = CREATEOBJECT("FormWithACombobox")
m.Test.Show(1)
BROWSE
DEFINE CLASS FormWithAComboBox AS Form
ADD OBJECT ACombo AS Combobox WITH Left = 10, Top = 10, ControlSource = "TestData.choice"
ADD OBJECT ATextField AS Textbox WITH Left = 10, Top= 40
ADD OBJECT DisplayCurrentValue AS Label WITH Left = 10, Top = 70, Autosize = .T., Caption = "Combo values will be shown here"
DIMENSION ComboValues(1)
FUNCTION ACombo.Init
ALINES(Thisform.ComboValues, "One, Two, Three, Four", 1, ",")
This.RowSourceType = 5
This.RowSource = "Thisform.ComboValues"
ENDFUNC
FUNCTION ACombo.Lostfocus
IF EMPTY(This.Value) AND !EMPTY(This.DisplayValue)
DIMENSION Thisform.ComboValues(ALEN(Thisform.ComboValues) + 1)
Thisform.ComboValues(ALEN(Thisform.ComboValues)) = ALLTRIM(This.DisplayValue)
This.Requery()
This.Value = ALLTRIM(This.DisplayValue)
ENDIF
Thisform.DisplayCurrentValue.Caption = This.Value
ENDFUNC
ENDDEFINE
----------------------------------
António Tavares Lopes