2 Replies Latest reply on Oct 25, 2010 6:15 AM by Flex Rock

    List Box Selection

    Flex Rock Level 1

      Hi,

           I have a list box. I need to get the previously selected item of that list box.Is it possible to get the previously selected Item from a list box.

       

      Thanks & Regards,

      Jayagopal.

        • 1. Re: List Box Selection
          BhaskerChari Level 4

          Hi Jayagopal,

           

          Please find the sample code below...

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

              <mx:Script>
                  <![CDATA[
                   import mx.events.ListEvent;
                   [Bindable]
                      public var prevSelectedItem:Object;
                     
                      [Bindable]
                      public var currSelectedItem:Object;
                     
                      private function listBoxChangeHandler(event:ListEvent):void
                      {
                       prevSelectedItem = currSelectedItem;
                       currSelectedItem = List(event.target).selectedItem;
                      }
                 ]]>
              </mx:Script>


              <mx:Model id="mystates">
                <states>
                  <state label="Alabama" data="AL"/>
                  <state label="Alaska" data="AK"/>
                  <state label="Arizona" data="AZ"/>
                  <state label="Arkansas" data="AR"/>
                  <state label="California" data="CA"/>
                  <state label="Colorado" data="CO"/>
                  <state label="Connecticut" data="CT"/>
                </states>
              </mx:Model>

              <mx:Panel title="List Control Example" height="75%" width="75%"
                  paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10">

                  <mx:Label text="Select a state to see its abbreviation."/>

                  <mx:List id="source" width="100%" color="blue"
                      dataProvider="{mystates.state}"
                      change="listBoxChangeHandler(event)"/>

                  <mx:VBox width="100%">
                      <mx:Label text="Current Selected State: {currSelectedItem.label}"/>
                      <mx:Label text="Current State abbreviation: {currSelectedItem.data}"/>
                      <mx:Spacer width="100%" height="25"/>
                      <mx:Label text="Previous Selected State: {prevSelectedItem.label}"/>
                      <mx:Label text="Previous State abbreviation: {prevSelectedItem.data}"/>
                  </mx:VBox>

              </mx:Panel>
          </mx:Application>

           

           

          Thanks,

          Bhasker

          • 2. Re: List Box Selection
            Flex Rock Level 1

            Thanks Bhasker, thanks for your help.

             

            Regards,

            Jayagopal.