Android Question B4X ComboBox Issue - Item ID

kokoroayo

Member
Licensed User
Hi all,

I have an issue using the combo box. After going through the various tutorials, I successfully implemented the combobox. However, I could not achieve what I needed. I load data from my database into the combobox successfully but I could not get the right data for use.

My table contains 2 fields ("ItemCategory - Varchar" and "CategoryID - Integer") with the following data:

CategoryID - ItemCategory
101 - Books
125 - Statioinery
243 - Furniture
....

I want to present the ItemCategory to the user and when an item is selected, the categoryID should be returned (just like in VB), eg. if user selects Furniture, the combobox should return 243

I have tried but could not find where to add the CategoryID field. I can only add the list and reference it by item index.

Can my requirement be achieved please?
If yes, I need a guide please.
 

mangojack

Well-Known Member
Licensed User
There are a couple of ways you can do this ... Populate 2 lists with your DB data, one with the IDs and one with the Item Desc.
Load the Combobox with your Items list as normal.

note : Your code will differ but this will give you an idea.
B4X:
    Private lstIDs, lstItems As List 'global
      
  
    '101 - Books , 125 - Statioinery, 243 - Furniture
    lstIDs.Initialize2(Array As Int(101,125,243))
    lstItems.Initialize2(Array As String("Books","Stationery","Furniture"))
  
    B4XComboBox1.SetItems(lstItems)
  

Sub B4XComboBox1_SelectedIndexChanged (Index As Int)
    Log(lstIDs.Get(Index))  
End Sub




Another way to achieve your task is to mock up your own Combobox (Label, Imageview with up/down arrow & a ListView)
You can populate the ListView as normal and set the return click value as the Item ID value.

ListView.JPG
 
Last edited:

kokoroayo

Member
Licensed User
Thank you very much mj.
Both solutions make real good sence to me.
However, I will go with option 1 for now due to time constraints. I shall work on option 2 in my free time and maybe put it up here for others' benefit.

Thanks to this wonderful house.
 
Top