PDA

View Full Version : DlgListBox.GetSelected return only the last selected item


Olivier Chivet
07-21-2008, 09:37 AM
Hi all,

First I'm new with TrueUpdate and LUA language.

I just downloaded the TrueUpdate 3.0 Trial version and try to use a ListBox in a dialog.
So I added a DlgListBox from the screen gallery in the wizard, changed the Style to "Checklist Box" and checked the "Multi select" option.
In the "On Next" action tab, I just want to display (for debug checking) the name of all selected items.

To do this, I added this code :
--------------------------------------
local Selected = DlgListBox.GetSelected(CTRL_LIST_BOX);
local index;
local value;

for index,value in Selected do
Dialog.Message( "Selection ", index..value, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
--------------------------------------
Even if I selected more than one Item, the GetSelected function always returned only the last item I selected.
Moreover, If I display the existing variable "nSelectedCount" (result of "DlgListBox.GetSelectedCount") it always display "1".

Could someone help me to obtain the complete list of selected items ?

Thanks a lot.

Olivier Chivet

Ulrich
07-21-2008, 11:33 AM
Hello,

DlgListBox.GetSelected returns a table only if the ListBox is not set to Checklist Box. See this instead:


for i = 1, DlgListBox.GetCount(CTRL_LIST_BOX) do
tProperties = DlgListBox.GetItemProperties(CTRL_LIST_BOX, i);
if (tProperties.Checked) then
Dialog.Message( "Selection ", i .."=" .. tProperties.Text, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
end
end


Ulrich

Olivier Chivet
07-22-2008, 05:46 AM
Hello upeters,

Thank you for your code, It works fine.

And sorry for my misunderstanding between "(Get)Selected" and "Checked".

DlgListBox.GetSelected returns a table only if the ListBox is not set to Checklist Box

It's not completly true. You can select more than one line in a ListBox with "Multi Select" option even if it has the "CheckList Box" style. Then the "GetSelected" function returns the correct list of item, checked or not.

Best regards.