You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mspecht <mw...@googlemail.com> on 2013/10/29 10:38:41 UTC

DataGrid Drag and Drop on empty grid

I found a problem while dragging an item from one grid to another grid which
has no items:

"RangeError: Index '1' specified is out of bounds.
	at
mx.collections::ListCollectionView/addItemAt()[/Users/justinmclean/Documents/ApacheFlex4.11.0/frameworks/projects/framework/src/mx/collections/ListCollectionView.as:591]"

As far as I understand the code the calculated dropIndex in LayoutBase
should be 0 and it is 1. The method looks like this:

/ protected function calculateDropIndex(x:Number, y:Number):int
    {
        // Always add to the end by default.
        return target.numElements;
    }/

If there is already an item in the target DataGrid the problem does not
occur.

I created a small example to reproduce the behaviour:

/<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
					   xmlns:s="library://ns.adobe.com/flex/spark" 
					   xmlns:mx="library://ns.adobe.com/flex/mx" width="650" height="500"
					   creationComplete="initApp();">
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<fx:Script>
		
	</fx:Script>
	
	<s:HGroup>
		<s:VGroup>
			<s:Label text="Available Albums"/>
			<s:DataGrid id="srcgrid" 
						 dragEnabled="true" 
						 dropEnabled="true" 
						 dragMoveEnabled="true">
				<s:ArrayList>
					<s:GridColumn dataField="Artist"/>
					<s:GridColumn dataField="Album"/>
					<s:GridColumn dataField="Price"/>
				</s:ArrayList>    
			</s:DataGrid>
		</s:VGroup>
		
		<s:VGroup>
			<s:Label text="Buy These Albums"/>
			<s:DataGrid id="destgrid"  
						 dragEnabled="true" 
						 dropEnabled="true" 
						 dragMoveEnabled="true">
				<s:ArrayList>
					<s:GridColumn dataField="Artist"/>
					<s:GridColumn dataField="Album"/>
					<s:GridColumn dataField="Price"/>
				</s:ArrayList>    
			</s:DataGrid>
		</s:VGroup>		
		
	</s:HGroup>
	
	<s:Button id="b1" 
			  label="Reset"
			  click="initApp()"
			  />
	
</s:WindowedApplication>/



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/DataGrid-Drag-and-Drop-on-empty-grid-tp3386.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.