B4J Question [Solved]Set Selected Value (String) in B4XComboBox

Peter Lewis

Active Member
Licensed User
Longtime User
Hi All ,

I have a B4xCombobox that I want to make the selected value a specific string that could be anywhere in the Combobox.

So I thought that there might be a Value option, There is not.

I have tried 'index of ' but that returns -1
indexOf:
Log(cmbProductSearch2.IndexOf(dtaSearchProduct.Text&"="&tblInvDetail.GetRow(RowId).Get("Description")))
or it could be 
Log(cmbProductSearch2.IndexOf(tblInvDetail.GetRow(RowId).Get("Product Code")&"="&tblInvDetail.GetRow(RowId).Get("Description")))

in populating the Combobox I have done

Populate Combobox:
Dim fullinfo As String = Cursor.GetString("InventoryCode")&"="&Cursor.GetString("InventoryDescription")
        cmbProductSearch2.cmbBox.Items.Add(fullinfo)

I have seen many times on the Forum that IndexOf should not be used.

This is the problem I am face with , it will show the correct product in the combobox but if the user does not select it , then it will be a null. I am trying to force the combobox to select the choice without user intervention.

1640030146427.png



Thank you for any advise
 
Last edited:

Peter Lewis

Active Member
Licensed User
Longtime User
Sorted using this approach

B4X:
Public Sub IndexOfString(value As String) As Int
    
    For j = 0 To cmbProductSearch2.cmbBox.Items.Size - 1
        Dim item As String = cmbProductSearch2.cmbBox.Items.Get(i)
        If item = value Then 
            Return j
        End If
    Next
    Return -1   
End Sub
 
Upvote 0
Top