ComboBox Value

RandomCoder

Well-Known Member
Licensed User
Longtime User
Hi Erel,

I have a form with several fields, some of these fields use ComboBox's to limit the choice to the user. I would like to be able to get the value from each ComboBox and the rest of the controls when the user clicks the finish button.

At present there appears to be two methods of doing this...
1) Use the SelectionChanged event on each ComboBox to obtain and store the value/text in a Global variable until the finish button is pressed.
2) On pressing the finish button, look at the SelectedIndex property for each ComboBox and then use a Select Case to determine what the actual value/text is.
Neither is particularly pretty.

It would be far better for me if I could just look at the value/text that has been selected when the finish button is pressed. Something like...

Field1Value=ComboBox1.Text

Is it possible to include a text property?? Maybe in the next version??

Regards,
RandomCoder
 

BjornF

Active Member
Licensed User
Longtime User
I don't understand, why do you need the "select case" (in your alternative 2)?

Doesn't this give the text from the combobox:
txt=ComboBox.Item(ComboBox.SelectedIndex)

(It does for me :) )
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Thanks BjornF,

That's exactly what I was after :sign0060: (albiet a slight workaround)

I was using...

txt=ComboBox.SelectedIndex

which just returns the position of the chosen item :sign0161:

Regards,
RandomCoder
 

specci48

Well-Known Member
Licensed User
Longtime User
A combobox has is no official .text property.
Is it a bug or an "undocumented feature" :confused:

I think it shouldn't be used because it may not be supported in future versions of basic4ppc.


specci48
 

rbw152

Member
Licensed User
Longtime User
Combo Text

Hi

actually this 'bug' is exactly what I want so don't 'fix' it please!

Here's the scenario: the user is selecting items (electrical device types) from a combo as they scan barcodes on the objects.

If an object type does not exist they need the ability to add it in the combo by typing it in - which the combobox allows you to do. Then I need to save that back to the lookup table so it's there next time, something which would be impossible if you couldn't access the combobox.text property!

Q. Why allow the user to type free-text into the combo if you then cannot access that text? Surely it should be locked to stop this if the text property is not supposed to be used?

Anyway, it's fine as it is, leave it alone please! :)
 

klaus

Expert
Licensed User
Longtime User
It is possible to change this behaviour with the Door library.
The code below alows entry of text.

You must load the Door library and define an object called obj1.
B4X:
obj1.New1(False)
obj1.FromControl"ComboBox1")
obj1.SetProperty("DropDownStyle","DropDown")
Best regards.
 
Top