数据源表格有2中类型的数据,需要拖入相对于类型的表格。 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="800" creationComplete="init();"> <mx:Script> <!--[CDATA[ import mx.collections.ArrayCollection; import mx.controls.Alert; import mx.events.DragEvent; //初始化数据 private function init():void{ var personArrayList:ArrayCollection = new ArrayCollection(); var infoData1:Object={personid:'1', name:'张三', tel:'13002300326',type:"person"}; var infoData2:Object={personid:'2', name:'王五', tel:'13663236985',type:"person"}; var infoData3:Object={personid:'3', name:'渝A5698', tel:'13654698546',type:"car"}; var infoData4:Object={personid:'4', name:'李四', tel:'13256985456',type:"person"}; var infoData5:Object={personid:'5', name:'渝A2698', tel:'13256985456',type:"car"}; personArrayList.addItem(infoData1); personArrayList.addItem(infoData2); personArrayList.addItem(infoData3); personArrayList.addItem(infoData4); personArrayList.addItem(infoData5); personList.dataProvider = personArrayList; } [Bindable] private var personlist:ArrayCollection = new ArrayCollection(); [Bindable] private var carlist:ArrayCollection = new ArrayCollection(); //添加类型为人员的到表格 protected function addPersonList_dragDropHandler(event:DragEvent):void { var array:Array = event.dragSource.dataForFormat("items") as Array; for each(var infodata:Object in array){ //如果拖拽对象的type为车辆就不允许添加到表格 if(infodata.type == 'car'){ event.preventDefault(); } } } //添加类型为车辆的到表格 protected function addCarList_dragDropHandler(event:DragEvent):void { var array:Array = event.dragSource.dataForFormat("items") as Array; for each(var infodata:Object in array){ //如果拖拽对象的type为人员就不允许添加到表格 if(infodata.type == 'person'){ event.preventDefault(); } } } ]]--> </mx:Script> <mx:VBox x="22" y="10" width="100%" height="100%"> <!--数据源表格--> <mx:DataGrid width="500" height="200" id="personList" fontSize="14" dragEnabled="true" dropEnabled="true"> <mx:columns> <mx:DataGridColumn headerText="personid" dataField="personid"/> <mx:DataGridColumn headerText="姓名" dataField="name"/> <mx:DataGridColumn headerText="电话" dataField="tel"/> <mx:DataGridColumn headerText="类型" dataField="type"/> <mx:DataGridColumn headerText="操作" dataField="op"/> </mx:columns> </mx:DataGrid> <!--人员表格--> <mx:DataGrid width="500" height="200" id="addPersonList" dataProvider="{personlist}" dragDrop="addPersonList_dragDropHandler(event)" fontSize="14" dragMoveEnabled="true" dragEnabled="true" dropEnabled="true"> <mx:columns> <mx:DataGridColumn headerText="personid" dataField="personid" /> <mx:DataGridColumn headerText="姓名" dataField="name"/> <mx:DataGridColumn headerText="电话" dataField="tel"/> <mx:DataGridColumn headerText="类型" dataField="type"/> <mx:DataGridColumn headerText="操作" dataField="op"/> </mx:columns> </mx:DataGrid> <!--车辆表格--> <mx:DataGrid width="500" height="200" id="addCarList" dataProvider="{carlist}" dragDrop="addCarList_dragDropHandler(event)" fontSize="14" dragMoveEnabled="true" dragEnabled="true" dropEnabled="true"> <mx:columns> <mx:DataGridColumn headerText="personid" dataField="personid"/> <mx:DataGridColumn headerText="车辆名称" dataField="name"/> <mx:DataGridColumn headerText="电话" dataField="tel"/> <mx:DataGridColumn headerText="类型" dataField="type"/> <mx:DataGridColumn headerText="操作" dataField="op"/> </mx:columns> </mx:DataGrid> </mx:VBox> </mx:Application>