Second column in Spinner?

I populate a spinner from a table of a database.
The table has two fields, id and name. In spinner we can see only the items of the column 'name'.
I want when an item is selected in spinner to get the id. (as you understand the table 's id is not the same with spinner 's SelectionIndex).

So, I was thinking, is there some way to add the column 'id' (as a hidden column) of the table in spinner? So that it 'l be very easy to get the id?

This might help ? (you may have to do the last part in reverse :wink: )

From what I understand, both columns are visible.
I want one of them to be hidden.

Do I have to do it for you ? Why not have a go at figuring it out.

The example I linked was just that, an example, but should help you to see what you need to do?

A dictionary is good for this, using names as keys and ids as values.

Populate the dictionary from the arriving table, and use it to look up the id after name selection.

1 Like

A simple example with dictionary blocks

4 Likes

I 'm trying to convert this to it 's db version (using Bennedum 's SQLite extension) without any success...

εικόνα

I get this error :confused::
εικόνα

Inventory_1_4_test_1.aia (119.9 KB)

Any help is welcome.

Please show an example of the content/schema of your database table "positions"
(your aia does not contain a database)

or share the file db.sqlite

OK, got it working

  1. In Screen1.properties tick the ShowListsAsJson checkbox (why is this unticked ?)
    image

  2. Drag in a web component, and use the JSON endcode AND JSON decode blocks to get the list of lists in the correct format

  3. Multiply the spinner selection number by 1 to get it to return the value
    image

Screen
image

db

image

It is sometimes worth spending a little money on an extension that is easy to work with, and works well :wink:

1 Like

Here is how it can be done using Taifun's sqlite extension, and without dictionaries (though they have their place...), plus some trickery on the spinner so that you can select the first item!
(using companion)

2 Likes