Does this work?

  private function removeSelected(): void {

    while (dgTest.selectedIndices.length > 0){
      acTest.removeItemAt(dgTest.selectedIndices[0]);
    }

  }


--- In flexcoders@yahoogroups.com, "Jim Robson" <[EMAIL PROTECTED]> 
wrote:
>
> OK, below is the solution that I came up with. If anyone sees a 
simpler /
> better way, please let me know.
> 
> Adobe engineers: I am guessing that removing items from a data 
grid is a
> common operation, in which case it seems like there should be a 
very simple
> and straightforward way of doing so. What am I missing?
> 
> private function sortOnInt(strA:String, strB:String):int {
> 
> var a:int = int(strA);
> 
> var b:int = int(strB);
> 
> var r:int = 0;
> 
> if(a > b) {
> 
> r = -1;
> 
> } else if(a < b) {
> 
> r = 1;
> 
> } else if(a == b) {
> 
> r = 0;
> 
> }
> 
> return r;
> 
> }      
> 
> private function removeSelected(): void {
> 
> var arr:Array = dgTest.selectedIndices;
> 
> arr.sort(sortOnInt);
> 
> for(var i:int = 0; i < arr.length; i++){
> 
> acTest.removeItemAt(arr[i]);
> 
> }
> 
> }
> 
>  
> 
>   _____  
> 
> From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> Behalf Of Jim Robson
> Sent: Thursday, June 08, 2006 11:21 AM
> To: flexcoders@yahoogroups.com
> Subject: RE: [flexcoders] Re: Remove selected items from an 
ArrayCollection
> / DataGrid?
> 
>  
> 
> Yes, I suspect you're on the right track (except for the fact that 
DataGrid
> indices are Strings – see my other post on that subject). 
> 
> The other issue I've encountered is that the array needs to be 
sorted from
> greatest to least. That's what I'm working on now. Of course, this 
is not
> straightforward either, because the DataGrid indices are strings!
> 
>  
> 
> Thanks for the help!!!
> 
>  
> 
>   _____  
> 
> From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> Behalf Of bhaq1972
> Sent: Thursday, June 08, 2006 11:14 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Re: Remove selected items from an 
ArrayCollection /
> DataGrid?
> 
>  
> 
> 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] <mailto:flexcoders%40yahoogroups.com> 
ups.com,
> "Jim Robson" <jim.robson@> 
> 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.
> <http://www.adobe.com/2006/mxml> 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>
> >
>







------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get to your groups with one click. Know instantly when new email arrives
http://us.click.yahoo.com/.7bhrC/MGxNAA/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