FLEX实践:DATAGRID中添加DOUBLECLICK事件

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()" backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#DBFAA6, #EFFDB5]">

<![CDATA[
import mx.events.FlexEvent;
import Class.CarVO;
import mx.collections.ArrayCollection;
import mx.controls.*;
import flash.events.*;

[Bindable]public var arr:ArrayCollection=new ArrayCollection();
private function init():void{
var car1:CarVO=new CarVO();
car1.name="Ford";
car1.age=2;
car1.available=false;
car1.applicationName="AC";
car1.applicationId=134;
var car2:CarVO=new CarVO();
car2.name="Buick";
car2.age=1;
car2.available=true;
car2.applicationName="AB";
car2.applicationId=135;
var car3:CarVO=new CarVO();
car3.name="BMW";
car3.age=2;
car3.available=true;
car3.applicationName="AA";
car3.applicationId=136;
arr.addItem(car1);
arr.addItem(car2);
arr.addItem(car3);

dg.addEventListener(MouseEvent.DOUBLE_CLICK,doubleClick);

}

private function doubleClick(evt:MouseEvent){
Alert.show(dg.selectedItem.applicationName+"--"+dg.selectedItem.applicationId)
}

]]>
</mx:Script>

<mx:DataGrid x="344" y="160" width="432" height="199" id="dg" dataProvider="{arr}" editable="false" doubleClickEnabled="true">
<mx:columns>
<mx:DataGridColumn dataField="available" headerText="Available">
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:CheckBox id="chxBox" selected="{data.available}" click="outerDocument.clickHandler(this);"/>
</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Name" dataField="name">
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:LinkButton label="{data.name}" click="outerDocument.show1();"
textDecoration="underline" color="#2066CF" fontWeight="normal"/>

</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="Age" dataField="age"/>
<mx:DataGridColumn headerText="Application" dataField="applicationName" editable="true">
<mx:itemRenderer>
<mx:Component>
<mx:HBox>
<mx:Label text="{data.applicationName}" id="applicationText" width="60%"/>
<mx:Button click="outerDocument.search();" width="40%"
icon="@Embed(source='images/search1.jpg')" />

</mx:HBox>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn headerText="ApplicationId" dataField="applicationId" />
</mx:columns>
</mx:DataGrid>
</mx:Application>

红色部分要记得添加哦。

你可能感兴趣的:(xml,Flex,Flash,Adobe)