View Full Version : Grid removing the model from store on Drag and Drop

10 Oct 2011, 4:22 AM

My requirement is when i drag drop on same Grid i should get the original index of dragged element and also the original index of dropped element as in the Grid's Store.

But i can see that when i drag an element from Grid that element is now been in Grid's Store anymore. Can you tell me how to stop this function?

As you can see i have overridden all the DnD events for my custom code. Still i dont know why i am getting this behavior from grid.

Below is the code.

/* Drag support */
GridDragSource documentDragSource = new GridDragSource(myGrid);
documentDragSource.addDNDListener(new DNDListener() {
public void dragStart(DNDEvent pDNDEvent) {}

/* Drop support */
GridDropTarget gridDropTarget = new GridDropTarget(myGrid);
gridDropTarget.addDNDListener(new DNDListener() {
public void dragDrop(DNDEvent pDNDEvent) {
DragSource dragSource = pDNDEvent.getDragSource();
if (dragSource instanceof GridDragSource) {
Grid grid = ((GridDropTarget)pDNDEvent.getDropTarget()).getGrid();

List<AbstractContentItem> selectedItems = pDNDEvent.getData();
int dragElementIndex = 0;
//here i am getting -1 only
dragElementIndex = grid.getStore().indexOf(selectedItems.get(selectedItems.size() - 1));

int rowIndex = grid.getView().findRowIndex(pDNDEvent.getDragEvent().getTarget());
if (dragElementIndex < rowIndex) {
rowIndex = rowIndex - 1;
AbstractContentItem contentItem = (AbstractContentItem)grid.getStore().getAt(rowIndex);
presenter.setSelectedNode(contentItem.getParentFolderDTO(), contentItem.getDTO());

public void dragEnter(DNDEvent pDNDEvent) {}

public void dragMove(DNDEvent pDNDEvent) {}


10 Oct 2011, 6:03 AM
Set the Operation to COPY. I set it as MOVE.