Get current value of combobox

Typically: "How do I... ", "How can I... " questions
Post Reply
Justus
Posts: 37
Joined: 24 Jan 2017, 07:37

Get current value of combobox

Post by Justus » 31 Aug 2018, 11:20

Hi,

I'm trying to retreive the index of the selected item in a combobox. However I cannot find this function in the API reference. Is there something like "simUI.getComboboxSelectedIndex" available?

Workaround I currently use is registering change events, but this is cumbersome.

-Justus

fferri
Posts: 223
Joined: 09 Sep 2013, 19:28

Re: Get current value of combobox

Post by fferri » 03 Sep 2018, 13:59

You can use simUI.getComboboxSelectedIndex to get the selected index, and simUI.getComboboxItemText to get the text at that index.

simUI.getComboboxSelectedIndex has been added on 5th June, so it may not be contained in the V-REP release.

Use the git repository https://github.com/CoppeliaRobotics/v_repExtCustomUI

Justus
Posts: 37
Joined: 24 Jan 2017, 07:37

Re: Get current value of combobox

Post by Justus » 04 Sep 2018, 13:19

Good to know the function is available. I prefer to use the official releases (so customers can download the tried and tested player).

Do you know when the next release is scheduled?

fferri
Posts: 223
Joined: 09 Sep 2013, 19:28

Re: Get current value of combobox

Post by fferri » 04 Sep 2018, 13:42

I have no idea about the date of next release, sorry.

If you want your code to work without the simUI.getComboboxSelectedIndex, you should use the "on-change" attribute of the combobox element, and store the new index in the event handler:

Code: Select all

function combo_changed(ui,id,idx)
    combo_index=idx
end

function button_click(ui,id)
    sim.addStatusbarMessage('combobox index: '..combo_index)
end

function sysCall_init()
    combo_index=0
    ui=simUI.create([[<ui>
        <combobox on-change="combo_changed">
            <item>one</item>
            <item>two</item>
            <item>three</item>
        </combobox>
        <button on-click="button_click" text="Click me" />
    </ui>]])
end

Justus
Posts: 37
Joined: 24 Jan 2017, 07:37

Re: Get current value of combobox

Post by Justus » 05 Sep 2018, 07:02

Thanks for your support; this is the method that I was using.

Maybe someone from Coppelia can tell us more about the release schedule?

Post Reply