2 Replies Latest reply on Mar 22, 2012 2:37 AM by Colijn1

    spark.List Control: right order in selectedItems

    Kalle Werning

      Hi there,


      How can I get the right order from the selectedItemsArray?


      The docs say:

      "These Vectors contain a list of the selected indices and selected data items in the reverse order in which they were selected. That means the first element in each Vector corresponds to the last item selected."


      But this is not correct. If you have a look in the example "Handling multiple selection in the Spark List control" at the end of
      you will see, that the order is switching around at every click you make to select an Item in the list.

      Indeed the last selected item is the first item in the array, but the order of the other items is not forseeable...


      My Problem:

      I'm using a list control as an itemeditor in a datagrid. (BTW: Is there a way to use dropshadow on the control?)

      The selectedItems are written to Database as a string in form of "firstselection : secondSelection : thirdSelection".


      I also already tried to push the last selectedItem in an array on every change event and join this to a string at focusOut.

      But that seems to be to late, because the datagridColums editorDataFiled doesn't take the the new values.

      Maybe there are other events , which would be better to use?


      Besides how to handle the prevoiuos selectedItems, which comes already from the db. The best would be, if they are already in the right order at the beginning of that array respectivelythe string. "prevSelectedItem1 : prevSelectedItem2 : newSelectedItem1 ..."


      Another solution would be to have at least the first selectedItem to be the first Item in the string to be written to the db whether is already selected at the editbeginnig or complete new selections are made.


      I hope its understandable, because I'm from Germany

      Every help is welcome!


      Thanks, Kalle!


                  <mx:DataGridColumn headerText="Fliesenart" dataField="prd_art" resizable="false" width="300" editorDataField="artLiSelected"  >

                      <mx:itemEditor >


                              <s:MXDataGridItemRenderer height="22" >



                                      import mx.collections.ArrayCollection;

                                      import mx.events.FlexEvent;


                                      import spark.events.IndexChangeEvent;



                                      public var artLiSelected:String;



                                      public var artTempArr:Array = new Array();


                                      public var artNewTempArr:Array = new Array();


                                      protected function artLi_creationCompleteHandler(artStr:String):void


                                          artLiSelected = artStr;

                                          artTempArr = artStr.split(" : ");


                                          var artTempVec:Vector.<Object> = new Vector.<Object>();


                                          for each (var art:Object in artTempArr) {



                                          artLi.selectedItems = artTempVec;





                                      protected function dataCollector():void {


                                          //artLiSelected = artLi.selectedItems.join(" : ");

                                          trace ("change");




                                      protected function dataSubmitter ():void {

                                          artLiSelected = artNewTempArr.join(" : ");

                                          trace ("focusOut");




                                  <s:List id="artLi" height="300" top="5" left="5" right="5"