Hi Malavika,
On click of the check box, update the flag in the data provider.
Then while moving data from the source to destination data grid, get
the data corresponding to all the selected check boxes.
Following is the code which does the same. You can modify this by
including data binding for the data provider of the grids.
I hope this is what you need.
**********************************************************************************************
<mx:CheckBox id="chkBoxSelectAll" x="54" y="39" label="Check to
Select All" color="#800000"
change="handleCheckBoxSelection();"/>
<mx:DataGrid id="mySourceDataGrid"
dataProvider="{mySourceDataProvider}" x="54" y="65" width="365">
<mx:columns>
<mx:DataGridColumn>
<mx:itemRenderer>
<mx:Component>
<mx:VBox paddingLeft="5">
<mx:CheckBox
label="{
data.name}" selected="{data.isRowSelected}"
click="outerDocument.updateSelectedRowFlag(event);"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="name"/>
<mx:DataGridColumn dataField="age"/>
<mx:DataGridColumn dataField="comment"/>
</mx:columns>
</mx:DataGrid>
<mx:Button id="btnMoveSelectedRows" x="421" y="126" height="28"
width="154"
label="Move Selected Rows >>" click="moveSelectedRows()"/>
<mx:DataGrid id="myDestinationDataGrid" x="579" y="65" width="365"
dataProvider="{myDestinationDataProvider}">
<mx:columns>
<mx:DataGridColumn>
<mx:itemRenderer>
<mx:Component>
<mx:VBox paddingLeft="5">
<mx:CheckBox
label="{
data.name}" selected="{data.isRowSelected}" enabled="false"/>
</mx:VBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="name"/>
<mx:DataGridColumn dataField="age"/>
<mx:DataGridColumn dataField="comment"/>
</mx:columns>
</mx:DataGrid>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var mySourceDataProvider:Array = new
Array({isRowSelected: false, name:'Name1', age:10,
comment:'Comment1'}, {isRowSelected: false, name:'Name2', age:20,
comment:'Comment2'}, {isRowSelected: false, name:'Name3', age:30,
comment:'Comment3'}, {isRowSelected: false, name:'Name4', age:40,
comment:'Comment4'});
private var myDestinationDataProvider:Array = [];
private function handleCheckBoxSelection():void
{
if(chkBoxSelectAll.selected)
{
chkBoxSelectAll.label = "Uncheck to De-
select All";
selectOrDeselect(true);
}
else
{
chkBoxSelectAll.label = "Check to Select
All";
selectOrDeselect(false);
}
}
private function selectOrDeselect(flgSelect:Boolean):void
{
var selIndicesArr:Array = [];
var dataProvLen:int = mySourceDataProvider.length;
for(var i:int = 0; i < dataProvLen; i++)
{
selIndicesArr.push(i);
mySourceDataProvider[i].isRowSelected =
flgSelect;
}
if(flgSelect)
{
mySourceDataGrid.selectedIndices =
selIndicesArr;
}
else
{
mySourceDataGrid.selectedIndices = [];
}
}
public function
updateSelectedRowFlag(event:MouseEvent):void
{
var currSource:CheckBox = CheckBox(event.currentTarget);
var selIndex:int;
if(currSource.selected)
{
selIndex = mySourceDataGrid.selectedIndex;
mySourceDataProvider[selIndex].isRowSelected = true;
}
else
{
selIndex = mySourceDataGrid.selectedIndex;
mySourceDataProvider[selIndex].isRowSelected = false;
}
}
private function moveSelectedRows():void
{
var selIndicesArr:Array = [];
var dataProvLen:int = mySourceDataProvider.length;
for(var i:int = 0; i < dataProvLen; i++)
{
if(mySourceDataProvider[i].isRowSelected)
{
selIndicesArr.push(i);
}
}
mySourceDataGrid.selectedIndices = selIndicesArr;
myDestinationDataProvider =[];
var noOfRowsSelected:int =
mySourceDataGrid.selectedIndices.length;
for(var j:int = 0; j < noOfRowsSelected; j++)
{
var selIndex:int = mySourceDataGrid.selectedIndices[j];
myDestinationDataProvider.push(mySourceDataProvider[selIndex]);
}
myDestinationDataGrid.dataProvider = myDestinationDataProvider;
}
]]>
</mx:Script>
</mx:Application>
**********************************************************************************************
Regards,
Easwara M
> ...
>
> read more »