P Peter Lewis Well-Known Member Licensed User Longtime User Dec 20, 2021 #1 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 Code: Copy 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 Code: Copy 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. Click to expand... Thank you for any advise Last edited: Dec 20, 2021
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 Code: Copy 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 Code: Copy 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. Click to expand... Thank you for any advise
P Peter Lewis Well-Known Member Licensed User Longtime User Dec 20, 2021 #2 Sorted using this approach B4X: Copy 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
Sorted using this approach B4X: Copy 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