B4J Question [SOLVED] B4XComboBox / How do I remove an item?

christianjeannot

Member
Licensed User
Hello community,

I am using this code to remove an item from a B4XComboBox and showing the first item.

B4X:
        Items.RemoveAt(ToDeleteIndex)
        cbProfile.SelectedIndex = 0

I still see the text from the removed index. Do I have to initialize again or how can I remove also the text from that index?

I have searched the guides, the examples I found and the forum but found no answer to this.

Best regards

--Christian
 

christianjeannot

Member
Licensed User
@Eme Fibonacci
Thank you for your testing.
From your code I guess it is necessary to address the B4XComboBox completely.
I do not make this in my code completely. I will test this in a small app.

How did you fill the B4XComboBox?
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
@Eme Fibonacci
Thank you for your testing.
From your code I guess it is necessary to address the B4XComboBox completely.
I do not make this in my code completely. I will test this in a small app.

How did you fill the B4XComboBox?

B4X:
For i = 1 To 10
       Items.Add($"Item #${i}"$)
 Next
 B4XComboBox1.SetItems(Items)

 
Upvote 0

christianjeannot

Member
Licensed User
I tested it.

I do not get Items.RemoveAt in the context from the B4XComboBox. The IDE tells me that there is no "item".
I have uploaded a small test project. Maybe you can check it.
I use XUIViews 2.44.
 

Attachments

  • Test_Upload.zip
    3.7 KB · Views: 160
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
The Items list is not directly linked to the B4XComboBox.
This code works in B4A and B4J, not tested in B4i.
B4X:
    Items.RemoveAt(ToDeleteIndex)
    cbHelper.SetItems(Items)
'   cbHelper.SelectedIndex=0 ' not needed
You need to set the Items list again to the B4XComboBox.

This code works in B4J:
B4X:
    cbHelper.cmbBox.Items.RemoveAt(ToDeleteIndex)
    cbHelper.SelectedIndex=0

This code works in B4A:
B4X:
    cbHelper.cmbBox.RemoveAt(ToDeleteIndex)
    cbHelper.SelectedIndex=0
 
Upvote 0

christianjeannot

Member
Licensed User
@klaus

many thanks for your information.

I did miss / not understand cmBox.

Meanwhile I tried this code without cmBox:

B4X:
Private Sub btnDelete_Click
        ToDeleteIndex = cbHelper.SelectedIndex
        'Log($"Selected Item Index: ${ToDeleteIndex}"$)
        Items.RemoveAt(ToDeleteIndex)
        cbHelper.SetItems(Items)
        cbHelper.SelectedIndex=0
End Sub

It worked in B4J. Is this ok?

I will test yours and mine in B4i as I need it there.
 
Upvote 0
Top