Here is a sample I wrote doing the deletion.

<mx:List id="mylist">

<mx:Array>
        <mx:Object label="Test Entry 1" />
        <mx:Object label="Test Entry 2" />
        <mx:Object label="Test Entry 3" />
        <mx:Object label="Test Entry 4" />
</mx:Array>

<mx:itemRenderer>
  <mx:Component>

    <mx:HBox>
        <mx:Script>
        <![CDATA[

        override public function set data(value:Object):void
        {
                 // set the label text
                status.text = value["label"];
                // set it on the button also so that we can use it
                // for deletion.
                closeBtn.data = value;
                super.data = value;
        }

        private function removeItem(data:Object):void
        {
                var index:int =
outerDocument.mylist.dataProvider.getItemIndex(data);
                                        
outerDocument.mylist.dataProvider.removeItemAt(index);
                                }
                        ]]>
                </mx:Script>
        
        <mx:Label id="status" />
        <mx:Button id="closeBtn" label="Close" click="removeItem(data)"/>
  </mx:HBox>
  
 </mx:Component>
</mx:itemRenderer>

</mx:List>


The idea is to use the data object passed to a itemRenderer. This data
 represents a item in the data provider. You can use the IList APIs on
the dataProvider to find the index and remove the item.

As I defined the itemRenderer inline I am using the outerDocument
property to access the list parent.

Let me know if it works for you.

-Sreenivas


--- In [email protected], "williamkusumo" <[EMAIL PROTECTED]>
wrote:
>
> Hi!
> 
> I have a List (populated via a dataProvider) and in each of the list
> items, I have a "Close" button. What is the best way to remove the
> item when the "Close" button is clicked? I understand I must remove
> the data from the dataProvider instead of just deleting the list item,
> but how do you get the index of the list item based on which button is
> clicked?
> 
> I have tried using the list's selectedIndex, but that's not really how
> you want to do it because the list item won't necessarily be the one
> selected when the "close" button is clicked (it'll screw up if you use
> keyboard to navigate to the button)
> 
> I have tried getting the list by using thebutton.parent.parent and
> then do a getChildIndex(...) passing in thebutton.parent. But all I
> got is the number "2" all the time no matter which item I clicked on.
> 
> Any help will be greatly appreciated.
> 
> Thanks!
>


Reply via email to