PDA

View Full Version : Multilistbox weird error...


antonv
11-20-2005, 05:10 AM
Hello everybody,

I'm trying to display the selected item in the listbox in a label but seems like there is an issue with the way multilistbox handles the selection of it's items!
Here is a sample code that gives the error:


mlbItems = #("A","B","C","D","E","F","G")
rollout test "test"
(
MultiListBox mlb "MultiListBox" selection:mlbItems.count items:mlbItems
label lbl "selection"
on mlb selected nameindex do
(
format "%\n" ((mlb.selection as array)[1] as string)
lbl.text = mlb.items[(mlb.selection as array)[1]]
)
)
createdialog test 200 200


When the rollout is created, the selected item is the last in the listbox. In the listener you'll see that the format command displays 2 values each time you change the selection! If you select towards the first item, everything works ok but in the moment you go back towards the last one, the script crashes because one of the values returned by the listbox is "undefined"!

Is there something that I'm missing or doing wrong here? Did anybody else encountered this before?

Light
11-20-2005, 05:19 AM
Maybe this does what you need:

mlbItems = #("A","B","C","D","E","F","G")
rollout test "test"
(
MultiListBox mlb "MultiListBox" selection:mlbItems.count items:mlbItems
label lbl "selection"
on mlb selected nameindex do lbl.text = mlbItems[nameIndex]
)
createdialog test 200 200




Light

antonv
11-20-2005, 05:26 AM
Thanks alot Light! I does exactly what I need! But I still don't understand why my code didn't work... Any clues on what happens in there?

Thanks!

Light
11-20-2005, 05:39 AM
I think it is because of the used event handler. This one seems to be a better choice if you want to go for a similar way:

mlbItems = #("A","B","C","D","E","F","G")
rollout test "test"
(
MultiListBox mlb "MultiListBox" selection:mlbItems.count items:mlbItems
label lbl "selection"
on mlb selectionEnd do lbl.text = mlbItems[(mlb.selection as array)[1]]
)
createdialog test 200 200




Light

antonv
11-20-2005, 05:44 AM
You are totally right! I should have payed more attention to the reference.

Thanks again!

CGTalk Moderation
11-20-2005, 05:44 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.