Android Question B4XComboBox event SelectedIndexChanged

andredamen

Active Member
Licensed User
Longtime User
How can I make it possible that SelectedIndexChanged event will be launched even if it doesn't change the index?
 

zed

Well-Known Member
Licensed User
If you want to trigger the action without using the event, perhaps you can call the method directly:
Call:
CallSubDelayed2(Me, "ComboBox1_SelectedIndexChanged", ComboBox1.SelectedIndex)
This should simulate the event without changing the index.
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Unfortunately, that doesn't work. I fill the combo box and then delete, for example, item 3 (with index 2). The combo box is repopulated. If I then select the third item again (with index 2), the sub isn't executed because the index is 2 again and therefore hasn't changed. I'd like to fix that problem.
I clear the cmbobox with cmbbox.clear but there should also be a cmbbox.clearindex.
 
Last edited:
Reactions: RJB
Upvote 0

mangojack

Expert
Licensed User
Longtime User
After you delete an item, then repopulate the combobox, Call B4XComboBox.SelectedItem = -1.

Unsure how it affects your flow.
 
Upvote 0

zed

Well-Known Member
Licensed User
If the user clicks "Item 1" again while "Item 1" is already selected, the native control doesn't generate a new event.

There's no standard, clean, and portable way in B4X to "intercept" this additional click with B4XComboBox.
If you really need a reaction on every open/selection, even if the item remains the same, the solution would be to create a custom ComboBox using xCustomListView.
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
@mangojack probably meant: B4XComboBox1.SelectedIndex = -1

Just noticed my typo ... Yes, should have been . SelectedIndex

Thought that if you cleared SelectedIndex, the Event would fire on subsequent same index selection.

Away from PC's for a couple of months (Bali ) ... So couldn't really check.
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
Paul, I tried 2 ways: cmbLijst.cmbBox.RemoveAt(xx) and completely clear and the fill the combobox again. And like Zed said there is no intercept when I delete the second item (index 3) and after refilling the combobox and click again the new box at item 2 (index 3).
 
Upvote 0

andredamen

Active Member
Licensed User
Longtime User
I found a solution: I use cmbLijst_SelectedIndexChanged(-1) and in the sub cmbLijst_SelectedIndexChanged get away as fast as I can: If Index = -1 Then Return This works!
 
Upvote 1
Cookies are required to use this site. You must accept them to continue using the site. Learn more…