Android Question B4XComboBox selectedindex only returns correct value within SelectedIndexChanged event

jimseng

Active Member
Licensed User
Longtime User
I am trying to fetch the currently selected index of a combo box from another subroutine, not the SelectedIndexChanged event. It seems that it only works once after the event has been triggered. From then on the result is always 0, regardless of which item is actually selected in the combo box. Is it possible to get the currently selected index of a combo box programmatically?
B4X:
Private Sub cmbHuman_SelectedIndexChanged (Index As Int)
    Log("index " & Index)
    Log("selectedIndexChanged " & cmbHuman.SelectedIndex)
End Sub
Log window:
index 1
selectedIndexChanged 1

B4X:
Sub getindexes()
    Log("selectedindex " & cmbHuman.SelectedIndex)
End Sub
Log window:
selectedindex 1 (first time subroutine is run after SelectedIndexChanged event)
selectedindex 0 (returns 0 until the item is changed)
 

jimseng

Active Member
Licensed User
Longtime User
My emails shows this response from Daestrum, but I can't see it on this thread for some reason.
Just tried the combobox it's working as expected
When first displayed combobox.SelectedIndex returns -1 >> none selected
After an entry is selected it returns the correct index (zero based)
Anyway, so it turns out I am an idiot. I was reloading the combobox each time I ran the test. Sorry to have wasted people's time.
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I did post then deleted it as I spotted it was Android you were asking about.
 
Upvote 0
Top