Flex DataGrid组件点选多行及获取数据实例
?
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
????? xmlns:s="library://ns.adobe.com/flex/spark"
????? xmlns:mx="library://ns.adobe.com/flex/halo"
????? minWidth="1024" minHeight="768"
????? creationComplete="init();">
<fx:Script>
?? <![CDATA[
??? private var xiangshengXMLList:XMLList = new XMLList();
???
??? public function init():void{
???? for(var i:int = 0; i < 5; i++){
????? xiangshengXMLList += <>
??????????? <myMusicXMLList>
???????????? <wode>
????????????? <musicNameColumn>{i + "仙剑奇侠传"}</musicNameColumn>
????????????? <musicSangColumn>{i}</musicSangColumn>
???????????? </wode>
??????????? </myMusicXMLList>
????????? ??? </>;
???? }
???? dataGridID.dataProvider = xiangshengXMLList.child("wode");
??? }
???
??? private function showSeleted():void{
?????? if(dataGridID.selectedItem != null){
??????? for(var i:int = 0; i < dataGridID.selectedItems.length; i++){
?????? trace(dataGridID.selectedItems[i].musicNameColumn);
????? }
???? }
??? }
???
?? ]]>
</fx:Script>
<!--先设置这两个属性allowDragSelection="true" allowMultipleSelection="true";按住Ctrl键再点选要选的行-->
<mx:DataGrid id="dataGridID" x="300" y="50" width="500" height="300" rollOverColor="red"
???? allowDragSelection="true" allowMultipleSelection="true">
?? <mx:columns>
??? <mx:DataGridColumn dataField="musicNameColumn" headerText="歌曲名"/>
??? <mx:DataGridColumn dataField="musicSangColumn" headerText="歌手"/>
?? </mx:columns>
</mx:DataGrid>
<mx:Button x="400" y="400" label="查看选中的行数据" click="showSeleted();"/>
</s:Application>