<?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/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.DragEvent;
private var adgTargetDp:ArrayCollection = new ArrayCollection();
<!--处理单击删除按钮事件 -->
protected function btnDel_clickHandler(event:MouseEvent):void
{
//获取用户选择行的书籍编号
var selIndex:int = this.adgTarget.selectedIndex;
if(selIndex<0)
{
Alert.show("没有选择行,不能删除","bookArrayCollection组件使用方法示例演示");
return;
}
this.bookArrayCollection.removeItemAt(selIndex);
}
protected function adgFrom_dragStartHandler(event:DragEvent):void
{
//将目标对象dropEnabled 置为true,表示允许拖放
this.adgTarget.dropEnabled = true;
}
protected function adgTarget_dragDropHandler(event:DragEvent):void
{
//获取用户拖放的数据行
var dgRow:Object = event.dragSource.dataForFormat("items")[0];
//如果拖放的目标数据在目标对象中
if(this.adgTargetDp.contains(dgRow))
{
Alert.show("目标对象已经存在此数据行!","拖放功能示例演示");
this.adgTarget.dropEnabled=false;
}
else
{
this.adgTargetDp.addItem(dgRow);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- 定义ArrayCollection实例,表示书籍列表-->
<s:ArrayCollection id="bookArrayCollection">
<fx:Object bookId="B001" bookType="程序" bookName="JAVA"/>
<fx:Object bookId="B002" bookType="程序" bookName="JSP"/>
<fx:Object bookId="B003" bookType="程序" bookName="FLEX"/>
<fx:Object bookId="B004" bookType="平面" bookName="PHOTOSHOP"/>
<fx:Object bookId="B005" bookType="平面" bookName="COREDRAW"/>
<fx:Object bookId="B006" bookType="办公" bookName="WORD"/>
<fx:Object bookId="B007" bookType="办公" bookName="EXCEL"/>
<fx:Object bookId="B008" bookType="办公" bookName="OUTLOOK"/>
</s:ArrayCollection>
</fx:Declarations>
<s:Panel horizontalCenter="0" verticalCenter="0" width="636" height="411" title="拖拽示例演示">
<mx:AdvancedDataGrid id="adgFrom" designViewDataType="tree" dataProvider="{bookArrayCollection}"
left="0" right="0" top="0" bottom="189" dragEnabled="true"
dragStart="adgFrom_dragStartHandler(event)">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="编号" dataField="bookId"/>
<mx:AdvancedDataGridColumn headerText="类型" dataField="bookType"/>
<mx:AdvancedDataGridColumn headerText="名称" dataField="bookName"/>
</mx:columns>
</mx:AdvancedDataGrid>
<mx:AdvancedDataGrid id="adgTarget" designViewDataType="tree" dropEnabled="true"
dragDrop="adgTarget_dragDropHandler(event)"
left="0" right="0" top="223" height="125">
<mx:columns>
<mx:AdvancedDataGridColumn headerText="编号" dataField="bookId"/>
<mx:AdvancedDataGridColumn headerText="类型" dataField="bookType"/>
<mx:AdvancedDataGridColumn headerText="名称" dataField="bookName"/>
</mx:columns>
</mx:AdvancedDataGrid>
<s:Rect left="0" bottom="0" right="0" height="30">
<s:fill>
<s:SolidColor color="#E2EDF7"/>
</s:fill>
</s:Rect>
<s:Button x="170" y="352" label="删除" click="btnDel_clickHandler(event)"/>
</s:Panel>
</s:Application>
Flex DataGrid 之间拖动
最新推荐文章于 2023-06-04 09:31:57 发布