|
The other day i was trying to get a list control to have multiple items set on startup however how to do this was not immediately obvious and after searching the web it seems quite a few other were having the same issue. Eventually I found the answer on Bruce Phillips blog, thanks a bunch Bruce! It basically boils down to doing this. Have a creation complete function on the application which will set the lists selected indices to an array... voila. Example...
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp();" width="243" height="429">
<mx:Script> <![CDATA[ import mx.collections.ArrayCollection;
[Bindable] public var aDemo:ArrayCollection = new ArrayCollection( [ {label:"me", data:"me"}, {label:"you", data:"you"}, {label:"boo", data:"a dog named boo"} ]);
private function initApp():void { //the array of selected indicies, this can be derived however you want. var aTmp:Array = new Array(0,2);
// set the selectedindicies... and thats it lstDemo.selectedIndices = aTmp; } ]]> </mx:Script>
<mx:List id="lstDemo" allowMultipleSelection="true" dataProvider="{aDemo}" ></mx:List>
</mx:Application> |