|
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 & 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> -- 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
YAHOO! GROUPS LINKS
|

