or similarly, but slightly different and with an assumption on the type of 
dataprovider. I'm sure there must be a better way though? I missed it if so.

       <mx:Script>
                <![CDATA[
                        private function selectAll():void
                        {                               
                                var selectedIndexArray:Array = new Array();
                                for (var i:int=0;i<myItems.length;i++)
                                {
                                        selectedIndexArray.push(i);
                                }
                                myList.selectedIndices = selectedIndexArray;
                        }
                ]]>
        </mx:Script>
        <mx:List id="myList" width="200" x="10" y="10" 
allowMultipleSelection="true" height="91">
                <mx:Array id="myItems">
                        <mx:String>test1</mx:String>
                        <mx:String>test2</mx:String>
                        <mx:String>test3</mx:String>
                        <mx:String>test4</mx:String>
                        <mx:String>test5</mx:String>
                        <mx:String>test6</mx:String>
                        <mx:String>test7</mx:String>
                </mx:Array>
        </mx:List>
        <mx:Button label="Select All" click="selectAll()"  y="109" x="10"/>




-----Original Message-----
From: flexcoders@yahoogroups.com on behalf of Josh McDonald
Sent: Thu 20/11/2008 22:55
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] How to SelectAll entries in List
 
Code:

var all : Array;

if (myList.dataProvider is Array)
{
  all = myList.dataProvider.concat();
}
else
{
  all = [];
  for (var o : * in myList.dataProvider)
  {
    all.push(o);
  }
}

myList.selectedItems = all;

Note that you might want to use myList.dataProvider.source() if it's a
collection of some sort, but that could backfire when sorts or filters are
applied. It might not, I haven't checked through the source or tested it,
but it might. YMMV, etc :)

-Josh

On Fri, Nov 21, 2008 at 8:32 AM, anuj181 <[EMAIL PROTECTED]> wrote:

> Hi Guys
> In the list allowMultipleSelection allows me to select multiple
> entries of the list box. How would i implement the 'Select All'
> functionality, I need all the entries of the list to be selected if I
> click on the button. Pls let me know
> Thanks in advance
> Anuj
>
>
> ------------------------------------
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Alternative FAQ location:
> https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups
> Links
>
>
>
>


-- 
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Like the cut of my jib? Check out my Flex blog!

:: Josh 'G-Funk' McDonald
:: 0437 221 380 :: [EMAIL PROTECTED]
:: http://flex.joshmcdonald.info/
:: http://twitter.com/sophistifunk


______________________________________________________________________
This communication is from Primal Pictures Ltd., a company registered in 
England and Wales with registration No. 02622298 and registered office: 4th 
Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT 
registration No. 648874577.

This e-mail is confidential and may be privileged. It may be read, copied and 
used only by the intended recipient. If you have received it in error, please 
contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 
1010. Please then delete the e-mail and do not disclose its contents to any 
person.
This email has been scanned for Primal Pictures by the MessageLabs Email 
Security System.
______________________________________________________________________

<<winmail.dat>>

Reply via email to