How to access list box selection?

I need help from the gurus to get past first base with the new dialog listbox. The following simple test code and associated resources are as far as I have got. When I run the code, the dialog pops up thus:


When I click item two:


The trace output is:

msg.event = selchange
ctl = lb1
label = undefined

How do I access the value/label of the item I clicked?

Once I get to grips with this, my next question will be how to pre-populate the list box before showing it for the first time. My test code has hard coded values of one, two, three, four in the resources. What I'd like to do is populate dynamically at run time.

Regards, AB

function OnClick(clickData) { DOpus.ClearOutput(); var dlg, ctl, i, max, str; dlg = DOpus.dlg; dlg.window = clickData.func.sourcetab; dlg.template = "dlg1"; dlg.detach = true; dlg.show; i = 0; max = 3; do { msg = dlg.getmsg(); ctl = msg.control; DOpus.output("msg.event = " + msg.event); DOpus.output("ctl = " + ctl); if (msg.event=="selchange") DOpus.output("label = " + ctl.label); i++; } while (i<max); // For safety while testing! }

<resources> <resource name="dlg1" type="dialog"> <dialog fontsize="8" height="100" lang="english" width="180"> <control height="40" name="lb1" type="listbox" width="64" x="12" y="10"> <contents> <item text="one" /> <item text="two" /> <item text="three" /> <item text="four" /> </contents> </control> <control checked="yes" height="10" name="rb1" title="Radio Button 1" type="radio" width="64" x="88" y="10" /> <control height="10" name="rb2" title="Radio Button 2" type="radio" width="64" x="88" y="22" /> <control height="14" name="b1" title="Button 1" type="button" width="50" x="19" y="61" /> </dialog> </resource> </resources>

The current selection could be in Dlg.Control(ctl.name).value since beta5, or it is in .index or selectedIndex, don't know what Jon decided on. How to create listitems could be described in the updated release notes. Dlg.Control("lb1").AddItem(label, value) should work, as should something like Dlg.Control("lb1").AddItem( ..CreateNewListItem(label, value) ), but I'd need to seek through the release notes pdf here as well to tell for sure.

PrePostEdit:
New API does not seem to be described in the release notes pdf yet, so maybe wait for the devs to tell you. o)

The selected index will be in msg.index and the name of the item will be in msg.value.

(or use dlg.Control(ctl).value as tbone says).

You're getting "undefined" from ctl.label because msg.control is a string, not a Control object.

Thanks @tbone and @jon for your assistance. I have updated the test code as follows and now need to understand how to get the value (e.g. three) of the selected item via the listbox control object. When I execute the code and click on item 3, the output is as per the screen grab. Every method seems to return the item's index.


Regards, AB

function OnClick(clickData) { DOpus.ClearOutput(); var dlg, ctl_name, ctl_obj, msg_obj, i, n, max, str; dlg = DOpus.dlg; dlg.window = clickData.func.sourcetab; dlg.template = "dlg1"; dlg.detach = true; dlg.show; i = 0; max = 3; do { msg_obj = dlg.getmsg(); DOpus.output("msg_obj.event = " + msg_obj.event); ctl_name = msg_obj.control; // The name of the control that was selected or clicked ctl_obj = dlg.control(ctl_name); // This control object if (msg_obj.event=="selchange") { DOpus.output("msg_obj.index = " + msg_obj.index); DOpus.output("msg_obj.value = " + msg_obj.value); n = ctl_obj.value; // For a list this is the item number DOpus.output("ctl_obj.value = " + n); str = ctl_obj.GetItemAt(n); DOpus.output("ctl_obj.GetItemAt(n) = " + str); str = ctl_obj.SelectItem(n); DOpus.output("ctl_obj.SelectItem(n) = " + str); } i++; } while (i<max); // For safety while testing! }

GetItemAt returns a DialogListItem object which has a number of properties including name.

I have printed the relevant Detached Dialogs page from Opus 12 Changes.pdf and the script control's object interface description from the 12.0.5 (Beta) Release History. is there anywhere else I should be looking for more detailed documentation? (I understand a lot of this is WIP and am happy to wait if that's the most sensible course of action).

Regards, AB

We haven't updated the PDF with the tbone-inspired changes yet but the help file is up-to-date, the examples have all been updated and the DialogListItem interface is described as well.

OK. Got it. I was looking under Scripting Reference --> Scripting Objects in the manual instead of the Script Objects section in the Directory Opus 12 specific reference. Smart boy wanted! :laughing:

Regards, AB

Good to know the *.chm has been updated, thanks! o)