[flexcoders] RE: Remove selected items from an ArrayCollection / DataGrid?

2006-06-08 Thread Jim Robson











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: 'flexcoders@yahoogroups.com'
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=$100Fix leaky
drain/service


service type=Electrical cost=$200Wire stairwell
lighting/service


service type=Roofing cost=$300Install vent pipe
boot/service


service type=Carpentry cost=$400Replace entry
door/service


service type=Plumbing cost=$500Install bath
tub/service


service type=Electrical cost=$600Wire home
office/service


service type=Roofing cost=$700Install ice
amp; water shield/service


service type=Carpentry cost=$800Install 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; idgTest.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




__._,_.___





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








   






  
  
SPONSORED LINKS
  
  
  

Web site design development
  
  
Computer software development
  
  
Software design and development
  
  


Macromedia flex
  
  
Software development best practice
  

   
  







  
  
  YAHOO! GROUPS LINKS



  Visit your group "flexcoders" on the web.
  To unsubscribe from this group, send an email to:[EMAIL PROTECTED]
  Your use of Yahoo! Groups is subject to the 

[flexcoders] Re: Remove selected items from an ArrayCollection / DataGrid?

2006-06-08 Thread bhaq1972
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 flexcoders@yahoogroups.com, 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: 'flexcoders@yahoogroups.com'
 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=$100Fix
 leaky drain/service
 
 service type=Electrical
 cost=$200Wire stairwell lighting/service
 
 service type=Roofing
 cost=$300Install vent pipe boot/service
 

RE: [flexcoders] Re: Remove selected items from an ArrayCollection / DataGrid?

2006-06-08 Thread Jim Robson










Yes, I suspect youre on the right
track (except for the fact that DataGrid indices are Strings  see my
other post on that subject). 

The other issue Ive encountered is
that the array needs to be sorted from greatest to least. Thats what Im
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]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.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:jim.[EMAIL PROTECTED].] 
 Sent: Thursday, June 08, 2006 9:14 AM
 To: 'flexcoders@yahoogroups.com'
 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=$100Fix
 leaky drain/service
 
 service type=Electrical
 cost=$200Wire stairwell lighting/service
 
 service type=Roofing
 cost=$300Install vent pipe boot/service
 
 service type=Carpentry
 cost=$400Replace entry door/service
 
 service type=Plumbing
 cost=$500Install bath tub/service
 
 service type=Electrical
 cost=$600Wire home office/service
 
 service type=Roofing
 cost=$700Install ice amp; water
shield/service
 
 service type=Carpentry
 cost=$800Install 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; 
idgTest.selectedIndices.length;
 i++){
 
 
 acTest.removeItemAt(dgTest.selectedIndices[i]);
 
 }
 
 }
 
 
 
 ]]
 
 /mx:Script
 
 mx:VBox width