Android Question B4XComboBox.SelectedIndex always return is 0

wachcio

New Member
Licensed User
Hello

I'm using B4XComboBox

Sub myComboBox_SelectedIndexChanged (Index As Int) working fine but myComboBox.SelectedIndex methods in others Subs return always "0". How can I check what the user chose?
 

mangojack

Expert
Licensed User
Longtime User
myComboBox.SelectedIndex methods in others Subs return always "0".

Without seeing some code it is difficult to help.

are u using a global variable ?

ie:
B4X:
Private iSelectedIndex as Int  'Global Var


Sub myComboBox_SelectedIndexChanged (Index As Int)
    iSelectedIndex = Index
    '................ more code ?


Sub  MyOtherSub( )
    Log(iSelectedIndex)
 
Upvote 0

wachcio

New Member
Licensed User
mangojack this working fine but it's possible not using global variable but use in other places in code myComboBox.SelectedIndex or myComboBox.SelectedItem?

B4X:
Sub button1_Click
 
  label1.Text = myComboBox.SelectedIndex 'always show 0
 
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
1. Are you choosing myComboBox before buttonClick ?
2. Are you always choosing 1st Item (index will always be 0)

Why must you use button click ?

B4X:
Sub myComboBox_SelectedIndexChanged (Index As Int)
    Label1.Text = myComboBox.GetItem(Index)

ps: if this does not help .. upload a small project ... File > Export as Zip
 
Upvote 0
Top