Sort ComboBox items : ComboBox Item « Components « Flex






Sort ComboBox items

Sort ComboBox items
       

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    initialize="initData();">
    <mx:Script>
        
        import mx.collections.*;
        public var myArray:Array = ["AZ", "MA", "MZ", "MN", "MO", "MS"];
        [Bindable]
        public var myAC:ArrayCollection;
        public function initData():void {
            myAC = new ArrayCollection(myArray);
        }
        public function MEMOFilter(item:Object):Boolean {
            return item >= "ME" && item <= "MO";
        }
        public function sortICV():void {
            var sort:Sort = new Sort();
            sort.fields=[new SortField(null, false, true)];
            myAC.filterFunction=MEMOFilter;
            myAC.sort=sort;
            myAC.refresh();
            myCB.selectedIndex=0;
            ta1.text="Sorted";
        }
        public function resetView():void {
            myArray = ["AZ", "MA", "MZ", "MN", "MO", "MS"];
            myAC = new ArrayCollection(myArray);
            ta1.text="Reset";
        }
      
    </mx:Script>
    <mx:ComboBox id="myCB" rowCount="7" dataProvider="{myAC}" />
    <mx:TextArea id="ta1" height="75" width="300" />
    <mx:HBox>
        <mx:Button label="Update View" click="initData();" />
        <mx:Button label="Sort View" click="sortICV();" />
        <mx:Button label="Reset View" click="resetView();" />
    </mx:HBox>
</mx:Application>

   
    
    
    
    
    
    
  








Related examples in the same category

1.ComboBox prepopulated with list itemsComboBox prepopulated with list items
2.Remove item at 0 position from a ComboBoxRemove item at 0 position from a ComboBox
3.Get Item index for a ComboBoxGet Item index for a ComboBox
4.Add Item to second position in a ComboBoxAdd Item to second position in a ComboBox
5.Add item to a ComboBoxAdd item to a ComboBox
6.ComboBox form itemComboBox form item