Get current value of combobox

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

Get current value of combobox

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: 440
Joined: 09 Sep 2013, 19:28

Re: Get current value of combobox

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: 42
Joined: 24 Jan 2017, 07:37

Re: Get current value of combobox

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: 440
Joined: 09 Sep 2013, 19:28

Re: Get current value of combobox

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)
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: 42
Joined: 24 Jan 2017, 07:37

Re: Get current value of combobox

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

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

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

Re: Get current value of combobox

Happy to see that simUI.getComboboxSelectedIndex is available in v3.6.0! (just a note: the online documentation does not mention the function)

coppelia