If you notice the selectedIndex of an mx:List or anything list based
for that matter, be it a, tree, combobox, or anything that is built of
the base List... whenever the dataprovider changes the selectedIndex
is lost....
say i want to bind my
<mx:List id="myList" selectedIndex="{customClass.someID}"> that way i
could have some values in that list, for example
price ranges:
100k - 200k
200k - 300k < this is selected for this house
300k - 400k
but in a different city i have
price ranges:
150k - 250k < this is selected for this house
250k - 400k
400k - 500k
so i'm binding to a custom class that i made, that grabs the current
price range of the house... but whenever my dataprovider changes, the
selected index is lost...
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var dp:ArrayCollection;
[Bindable]
public var source:ArrayCollection;
public function init():void
{
dp = new ArrayCollection([
{label: "item 1", data: 1},
{label: "item 2", data: 2}
]);
source = new ArrayCollection([
{label: "item 3", data: 3},
{label: "item 4", data: 4}
]);
}
public function handleChange():void
{
myList.dataProvider = source;
}
]]>
</mx:Script>
<mx:List x="10" y="10" id="myList" dataProvider="{dp}"
selectedIndex="1" width="200"/>
<mx:Button x="250" y="58" label="Button" click="handleChange()"/>
</mx:Application>
Any suggestions... I know my options... but it's more work than i
would like to do, i have a lot of code that i would have to change the
functionality if i were to create the form as an actionscript class,
and call the form field explicitly to change the selectedIndex
programatically... I could do that, and know how to... unfortunately i
didnt find out how to do that until i had made this... otherwise i
would have done that first... because it takes care of exceptions like
these... Is there any other option than spending 20 hours retooling my
components?