PDA

View Full Version : ListBox Woes


John-oh
11-03-2003, 11:42 AM
I am using a ListBox to open various (predefined) files.

I am using a suggested script (modified) from the help files "how do I?"

I have a ListBox with a button underneath, with the following code 'on press'

selected = ListBox.GetSelectedCount("ListBox1");
file = ListBox.GetItemData("ListBox1", selected);
if file == "" then
Dialog.Message("Notice", "You must select a file from the list above ...", MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);
else
File.Open(file, "", SW_SHOWNORMAL);
end

The dialog message works Ok, when no file selected.

But, I always get the file that is first on the list (position 1), no matter which file is selected in the list box.

I've tried various tweaks, like setting selected="" at the begining and reseting the list at the end, but it makes no difference.
I assume by now that I'm missing something blindingly obvious.

Anyone help ?

Cheers:(

Lorne
11-03-2003, 11:59 AM
You're using GetSelectedCount()...which returns the number of items that are currently selected.

Then you use that "count" as the index of the item...oops.

You want to use GetSelected instead.

Try this instead:

tSelected = ListBox.GetSelected("ListBox1");
file = ListBox.GetItemData("ListBox1", tSelected[1]);

...although if you have the listbox set up to allow multiple selection, you should rewrite your code to go through the tSelected table and open all of the selected files.

John-oh
11-03-2003, 02:02 PM
Lorne,

Excellent, all works as expected now.

Thanks.

I beleive that makes the Helpfile section :

How do I ? - Create a file browser - incorrect, as thats where I got the script from.

Thanks again.

Darryl
11-03-2003, 02:51 PM
Thanks, we'll get that fixed up.