B4J Question Check if ComboBox contains a specific value (SOLVED)

Colin Evans

Active Member
Licensed User
Longtime User
Is there a way to check if a specific string value is contained in a combobox, if not then add the value , thanks
 

josejad

Expert
Licensed User
Longtime User
Hi:

Something like this?

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private B4XComboBox1 As B4XComboBox
    Private List1 As List
End Sub

Public Sub Initialize
    '    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    List1.Initialize
    List1.AddAll(Array As String("Apple", "Banana", "Cocoa"))
    B4XComboBox1.SetItems(List1)
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    If B4XComboBox1.IndexOf("Cucumber") = -1 Then
        List1.Add("Cucumber")
        B4XComboBox1.SetItems(List1)
        
    End If
End Sub
[code]
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Is there a way to check if a specific string value is contained in a combobox, if not then add the value , thanks
B4X:
Dim items as list = combobox.items
for each item as string in items
    if item = "Value"  then
        log("Value is contained")
    end if
Next
 
Upvote 0

Xandoca

Active Member
Licensed User
Longtime User
third way to do it:
B4X:
Sub existsoradd(item As String)
    If B4XComboBox1.IndexOf(item) = -1 Then
        B4XComboBox1.cmbBox.Items.Add(item)
    End If
End Sub

Remember to check that:
B4X:
Sub B4XComboBox1_SelectedIndexChanged (Index As Int)
    If B4XComboBox1.cmbBox.SelectedIndex <> -1 Then
        ...
    End If
End Sub
 
Upvote 0
Top