Android Question B4XComboBox, select item '0' problem

Mostez

Well-Known Member
Licensed User
Longtime User
I use this code to select one of values listed in combobox and put it in textbox, when I try to select the first item in combobox, the event never fired, I have to select another item and then select item 0 again! is there something to do to solve this problem.

B4X:
Sub cmbFieldValues_SelectedIndexChanged (Index As Int)
    txtValue1.Text = cmbFieldValues.SelectedItem
 

JohnC

Expert
Licensed User
Longtime User
When the combobox is first displayed, does it already display the "first item"? If so, then the event is not triggering because by tapping on the *already* displayed first item, the combobox index does not actually change, and that's why the event doesn't get triggered.

Try making the first item in the combobox be "[make a selection]" and then fill it with your other items, which will actually then make your first item be the "second" item in the combobox. This will then force the user to change the combo from displaying "[make a selection]" to then select your first item, which will trigger the event.
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
when I try to select the first item in combobox, the event never fired, I have to select another item and then select item 0 again
In Activity_Create put this line: cmbFieldValues_SelectedIndexChanged (0)
Without adding a new item to the list, then make the sub like this:
B4X:
Sub cmbFieldValues_SelectedIndexChanged (Index As Int)
    txtValue1.Text=B4XComboBox1.GetItem(Index)
End Sub
If John's solution does what you wanted, please ignore this post.
 
Upvote 1
Top