Hi Flexcoders,
I am on Flex 2.0.1 SDK.
My use case is as follows:
1) At the start of the application, I set dataproviders of
XMLListCollection type to 2 different UI controls on stage (<mx:Tree>
and <mx:List>) and then I set immediately selectedIndexes to 0.
It works all right for both controls.
2) Then I switch dataproviders at the runtime for both UI controls by
pressing the button and then I set immediately selectedIndexes to 0
again.
<mx:List> displays the selection correctly, while <mx:Tree> does not.
My current workaround is to set myTree.selectedIndex = 0 within
"callLater" call or within FlexEvent.UPDATE_COMPLETE event listener
for mx:Tree.
My test file is quite simple:
-------------------
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
initialize="onInitialize()">
<mx:Script>
<![CDATA[
private function onInitialize() : void {
tree1.dataProvider = capitals;
list2.dataProvider = capitalColl;
setSelectedIndexes();
}
private function changeDP() : void {
tree1.dataProvider = capitals2;
list2.dataProvider = capitalCol2;
setSelectedIndexes();
//callLater(setSelectedIndexes)
}
private function setSelectedIndexes() : void {
tree1.selectedIndex = 0;
list2.selectedIndex = 0;
}
]]>
</mx:Script>
<mx:XML id="capitals">
<root>
<Capitals label="U.S. State Capitals">
</Capitals>
<Capitals label="Canadian Province Capitals">
</Capitals>
</root>
</mx:XML>
<mx:XML id="capitals2">
<root>
<Capitals label="U.S. State Capitals-2">
</Capitals>
<Capitals label="Canadian Province Capitals-2">
</Capitals>
</root>
</mx:XML>
<!-- Create an XMLListCollection representing the Tree nodes.
capitals.Capitals is an XMLList with both Capitals elements. -->
<mx:XMLListCollection id="capitalColl" source="{capitals.Capitals}"/>
<mx:XMLListCollection id="capitalCol2" source="{capitals2.Capitals}"/>
<mx:Tree id="tree1"
labelField="@label"
showRoot="false"
width="300"/>
<!-- The XMLListCollection does not include the XML root. -->
<mx:List id="list2"
labelField="@label"
width="300"/>
<mx:Button id="btn1" label="Change data provider" click="changeDP()">
</mx:Button>
</mx:Application>
-------------------
--
Med venlig hilsen / Best regards
Andriy Panas
[EMAIL PROTECTED]