2 Replies Latest reply on Aug 16, 2011 2:24 PM by ChristophFlex

    Selecting mulitple items in a List programmaticly

    ChristophFlex

      Hi everyone,

       

      my list doesn't shows my updates if i select a item programmaticly.

       

       

      this is an easy example showing my problem:

       

          <fx:Script>
              <![CDATA[


                  import mx.collections.ArrayList;
                  import mx.events.FlexEvent;


                  [Bindable]
                  public var array:ArrayList=new ArrayList();
                 
                  protected function view1_initializeHandler(event:FlexEvent):void
                  {
                      array.addItem("item 1");
                      array.addItem("item 2");
                      array.addItem("item 3");
                      array.addItem("item 4");
                      array.addItem("item 5");
                  }
                 
                  protected function view1_creationCompleteHandler(event:FlexEvent):void
                  {
                      list.selectedIndices.push(1);
                      list.selectedIndices.push(2);
                      list.selectedIndices.push(4);
                  }
                 
              ]]>
          </fx:Script>
         
          <s:List width="100%" height="100%" dataProvider="{array}" allowMultipleSelection="true" id="list">
             
          </s:List>

       

      The list doesn't show any selected items on prgramm start, but if i click for example item 3 or 5 which isnt in the selectedIndices array yet, item 1,2 and 4 becomes visual selected too. Seems like i have too tell the list somehow that it should check its selectedIndices vector if i select an item programmaticly.