Retaining list selectedIndex between data binding reloads in Flex

actionscript-3apache-flexdata-binding

In my Flex interface, I've got a few List components that are data bound to ArrayCollections. I'm finding that when the ArrayCollections are updated (by Web services) and the data bindings for the Lists update, each List is reset and its selectedIndex is dropped. This is a problem if a user is in the middle of a task and has already selected an item in the List, but hasn't yet submitted the form.

I know how I can kludge together some ActionScript to deal with these cases, but do you know of any way to handle this more naturally using Flex's data binding or general-purpose event utilities?

As always, thanks!

Best Answer

I like using the observe class found here to call a function when data changes. It takes two parameters: data to watch, and a function to call. (Saves you time of repeating setters and getters all the time)

I would stored the selectedItem when it is selected and when the data is updated reselect this item by looping through the list and selecting the item again.