Hi
please review the below code will work for all list components no need
to loop the dataprovider of list,try this code let me know if you have
any doubts

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="horizontal" initialize="init()">
<mx:Script>
        <![CDATA[
                import mx.events.ListEvent;
                import mx.events.ItemClickEvent;
                import mx.collections.ArrayCollection;
                import mx.controls.Alert;
                [Bindable]
                public var listMenu:ContextMenu;
                [Bindable]
                public var selectedIndexVar:int = -1;
                [Bindable]
                public var sampleData:ArrayCollection = new
ArrayCollection([{label:"one"},{label:"two"},{label:"three"},
{label:"four"},{label:"five"}]);
                public function init():void
                {
                        listMenu = new ContextMenu();
                        listMenu.hideBuiltInItems();
                        var menuItems:ContextMenuItem = new 
ContextMenuItem("Remove Item");
        
menuItems.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,handler);
                        listMenu.customItems = [menuItems];
                }
                public function handler(event:ContextMenuEvent):void
                {
                   //contextMenuOwner returns the list object in this
scenario
                        ((event.contextMenuOwner as List).dataProvider as
ArrayCollection).removeItemAt(selectedIndexVar);
                        Alert.show("item selected");
                }
                public function itemRollOvewr(event:ListEvent):void
                {
                        selectedIndexVar = event.rowIndex;
                }
        ]]>
</mx:Script>
<mx:List contextMenu="{listMenu}" selectedIndex="{selectedIndexVar}"
itemRollOver="itemRollOvewr(event)"
        id="lst" dataProvider="{sampleData}" labelField="label">
</mx:List>

</mx:Application>
Regards
Santosh Kumar
http://techflex.blog.com

-- 
You received this message because you are subscribed to the Google Groups "Flex 
India Community" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/flex_india?hl=en.

Reply via email to