Get current value of combobox

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

Get current value of combobox

Post 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

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

Re: Get current value of combobox

Post 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

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

Re: Get current value of combobox

Post 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?

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

Re: Get current value of combobox

Post 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

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

Re: Get current value of combobox

Post 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?

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

Re: Get current value of combobox

Post by Justus »

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

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: Get current value of combobox

Post by coppelia »

Thanks for mentioning this too, the doc has been fixed!

Cheers

Post Reply