Saturday, October 11, 2008

Flex ArrayCollection and addItemAt() problem

The other day I was banging my head, for adding an item to the ArrayCollection Object at zero th index.  The item simple adds to the end of the list, but I want to add it to the start of the arraycollection.

The case scenarion is like this:

 var col:ICollectionView = new ArrayCollection();      col.addItem("California");      col.addItem("Arizona");      var sort:Sort = new Sort();      // There is only one sort field, so use a null first parameter.      sort.fields = [new SortField(null, true)];      col.sort = sort;      col.refresh();
//now add an item at the 0 th index
col.addItemAt("Alaska",0);
//The above statment simply fails, it adds the item at last position
//The reason is you cannot use addItemAt() after applying a sort to the ArrayCollection. It simply
// adds to the end. Ignore either sorting or adding an item.



No comments: