i reckon your the selectedIndicis is changing and therefore cannot 
be relied upon within your for loop.

try this. (as a starting point)

private function removeSelected():void
{
 var array1:Array = new Array();
 for(var j:int;j < dgTest.selectedIndices.length; j++)
 {
   var num1:int = dgTest.selectedIndices[j];
        
   array1.push(num1);
 }
 
 for(var i:int = 0; i < array1.length; i++)
 {
        acTest.removeItemAt(array1[i]);
 }
}



--- In [email protected], "Jim Robson" <[EMAIL PROTECTED]> 
wrote:
>
> Correction: the app is actually removing ½ of the selected items 
with each
> click of the button. The new version of the code below has 
additional items
> in the data model in order to make this easier to test. 
> 
>  
> 
> Any ideas? Am I just missing something obvious?
> 
>  
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; >
> 
>             
> 
>             <mx:Model id="mTest">
> 
>                         <services>
> 
>                                     <service type="Plumbing" 
cost="$100"
> description="Fix leaky drain" />
> 
>                                     <service type="Electrical" 
cost="$200"
> description="Wire stairwell lighting"/>
> 
>                                     <service type="Roofing" 
cost="$300"
> description="Install vent pipe boot"/>
> 
>                                     <service type="Carpentry" 
cost="$400"
> description="Replace entry door"/>
> 
>                                     <service type="Plumbing" 
cost="$500"
> description="Install bath tub"/>
> 
>                                     <service type="Electrical" 
cost="$600"
> description="Wire home office"/>
> 
>                                     <service type="Roofing" 
cost="$700"
> description="Install ice &amp; water shield"/>
> 
>                                     <service type="Carpentry" 
cost="$800"
> description="Install sliding patio door"/>
> 
>                                     <service type="Plumbing" 
cost="$900"
> description="Install hot tub"/>
> 
>                                     <service type="Electrical" 
cost="$1000"
> description="Install service box"/>
> 
>                                     <service type="Roofing" 
cost="$1100"
> description="Shingle one-car garage"/>
> 
>                                     <service type="Carpentry" 
cost="%1200"
> description="Build small deck"/>
> 
>                         </services>
> 
>             </mx:Model>
> 
>             <mx:ArrayCollection id="acTest"
> source="{mTest.services.service}" />
> 
>             
> 
>             <mx:Script>
> 
>                         <![CDATA[
> 
>                                     import 
mx.collections.ArrayCollection;
> 
>             
> 
>             private function removeSelected():void{
> 
>                         for(var i:int = 0; i <
> dgTest.selectedIndices.length; i++){
> 
>  
> acTest.removeItemAt(dgTest.selectedIndices[i]);
> 
>                         }
> 
>             }
> 
>             
> 
>                         ]]>
> 
>             </mx:Script>
> 
>             
> 
>             <mx:VBox width="400" height="600">
> 
>             
> 
>                         <mx:DataGrid id="dgTest" 
dataProvider="{acTest}"
> width="400" height="500" allowMultipleSelection="true">
> 
>                                     <mx:columns>
> 
>                                                 <mx:DataGridColumn
> headerText="Type" dataField="type"  />
> 
>                                                 <mx:DataGridColumn
> headerText="Service" dataField="description"  />
> 
>                                                 <mx:DataGridColumn
> headerText="Cost" dataField="cost"  />
> 
>                                     </mx:columns>
> 
>                         </mx:DataGrid>
> 
>                         
> 
>                         <mx:Button id="btnTest" 
click="removeSelected();"
> label="Remove Selected" />
> 
>                         
> 
>             </mx:VBox>
> 
>             
> 
>  
> 
> </mx:Application>
> 
>  
> 
>   _____  
> 
> From: Jim Robson [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, June 08, 2006 9:14 AM
> To: '[email protected]'
> Subject: Remove selected items from an ArrayCollection / DataGrid?
> 
>  
> 
> I am trying to give users the ability to remove selected items 
from a
> DataGrid. The idea is that the user selects the items to remove, 
then clicks
> the "Remove Selected" button. The problem is that if the user 
selects more
> than one item, then not all of the selected items will be removed. 
If the
> user selects 3 items, the app usually removes 2 of them (although 
it
> occasionally only removes 1). If the user selects 4 items, it 
usually
> removes 3, and so forth. 
> 
>  
> 
> Can anyone see the problem in the code below? 
> 
>  
> 
> <?xml version="1.0" encoding="utf-8"?>
> 
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; >
> 
>             
> 
>             <mx:Model id="mTest">
> 
>                         <services>
> 
>                                     <service type="Plumbing" 
cost="$100">Fix
> leaky drain</service>
> 
>                                     <service type="Electrical"
> cost="$200">Wire stairwell lighting</service>
> 
>                                     <service type="Roofing"
> cost="$300">Install vent pipe boot</service>
> 
>                                     <service type="Carpentry"
> cost="$400">Replace entry door</service>
> 
>                                     <service type="Plumbing"
> cost="$500">Install bath tub</service>
> 
>                                     <service type="Electrical"
> cost="$600">Wire home office</service>
> 
>                                     <service type="Roofing"
> cost="$700">Install ice &amp; water shield</service>
> 
>                                     <service type="Carpentry"
> cost="$800">Install sliding patio door</service>
> 
>                         </services>
> 
>             </mx:Model>
> 
>             <mx:ArrayCollection id="acTest"
> source="{mTest.services.service}" />
> 
>             
> 
>             <mx:Script>
> 
>                         <![CDATA[
> 
>                                     import 
mx.collections.ArrayCollection;
> 
>             
> 
>             private function removeSelected():void{
> 
>                         for(var i:int=0; 
i<dgTest.selectedIndices.length;
> i++){
> 
>  
> acTest.removeItemAt(dgTest.selectedIndices[i]);
> 
>                         }
> 
>             }
> 
>             
> 
>                         ]]>
> 
>             </mx:Script>
> 
>             <mx:VBox width="400" height="600">
> 
>             
> 
>                         <mx:DataGrid id="dgTest" 
dataProvider="{acTest}"
> width="400" height="500" allowMultipleSelection="true">
> 
>                                     <mx:columns>
> 
>                                                 <mx:DataGridColumn
> headerText="Type" dataField="type"  />
> 
>                                                 <mx:DataGridColumn
> headerText="Service" dataField="service"  />
> 
>                                                 <mx:DataGridColumn
> headerText="Cost" dataField="cost"  />
> 
>                                     </mx:columns>
> 
>                         </mx:DataGrid>
> 
>                         
> 
>                         <mx:Button id="btnTest" 
click="removeSelected();"
> label="Remove Selected" />
> 
>                         
> 
>             </mx:VBox>
> 
>             
> 
>  
> 
> </mx:Application>
>







------------------------ Yahoo! Groups Sponsor --------------------~--> 
You can search right from your browser? It's easy and it's free.  See how.
http://us.click.yahoo.com/_7bhrC/NGxNAA/yQLSAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to