Allow Multiple Selection for AdvancedDataGrid
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
import mx.collections.ArrayCollection;
import flash.events.KeyboardEvent;
import flash.system.System;
[Bindable]
private var dpADG:ArrayCollection = new ArrayCollection([
{Artist:'A', Album:'aa', Price:1.99},
{Artist:'J', Album:'jj', Price:1.99},
{Artist:'K', Album:'kk', Price:1.99}
]);
private function myKeyUpHandler(event:KeyboardEvent):void
{
var keycode_c:uint = 67;
if (event.ctrlKey && event.keyCode == keycode_c)
{
var dataString:String = "";
var n:int = event.currentTarget.selectedCells.length;
for (var i:int = 0; i < n; i++)
{
var cell:Object = event.currentTarget.selectedCells[i];
var data:Object = event.currentTarget.dataProvider[cell.rowIndex];
var dataField:String = event.currentTarget.columns[cell.columnIndex].dataField;
dataString = data[dataField] + ' ' + dataString;
}
System.setClipboard(dataString);
}
}
</mx:Script>
<mx:AdvancedDataGrid width="100%"
height="100%"
dataProvider="{dpADG}"
selectionMode="multipleCells"
allowMultipleSelection="true"
keyUp="myKeyUpHandler(event);">
<mx:columns>
<mx:AdvancedDataGridColumn dataField="Artist" />
<mx:AdvancedDataGridColumn dataField="Album" />
<mx:AdvancedDataGridColumn dataField="Price" />
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
Related examples in the same category