Page 1 of 1

Get current value of combobox

Posted: 31 Aug 2018, 11:20
by Justus
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

Re: Get current value of combobox

Posted: 03 Sep 2018, 13:59
by fferri
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

Re: Get current value of combobox

Posted: 04 Sep 2018, 13:19
by Justus
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?

Re: Get current value of combobox

Posted: 04 Sep 2018, 13:42
by fferri
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

Re: Get current value of combobox

Posted: 05 Sep 2018, 07:02
by Justus
Thanks for your support; this is the method that I was using.

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