This is a migrated thread and some comments may be shown as answers.

Drag Drop of last item (level n; n<>0) in the treeview adds it as a sibiling to level 0 items of the treeview

0 Answers 31 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Jay
Top achievements
Rank 1
Jay asked on 25 May 2012, 06:09 AM
Hi,

We had a requirement as follows:
An item can be moved around among its sibilings below the same parent only.

if (e.TargetDropItem != null  && draggedItems != null && draggedItems.Count > 0 )
            {
                Node targetNode = (Node)(e.TargetDropItem.Header);
                if (e.TargetDropItem.ParentItem != null && targetNode != draggedItems[0] as Node)
                {
                    if (e.DropPosition == DropPosition.After || e.DropPosition == DropPosition.Before)
                    {                       
                        if (targetNode.ParentNode != (draggedItems[0] as Node).ParentNode)
                        {
                            e.TargetDropItem.ParentItem.IsDropAllowed = false;
                        }
                        else
                        {
                            e.TargetDropItem.ParentItem.IsDropAllowed = true;
                        }
                    }
                    else if (e.DropPosition == DropPosition.Inside)
                    {
                        if (e.TargetDropItem == draggedItems[0] ||
                            targetNode != (draggedItems[0] as Node).ParentNode)
                        {
                            e.TargetDropItem.IsDropAllowed = false;                          
                        }
                        else
                        {
                            e.TargetDropItem.IsDropAllowed = true;
                        }
                    }
                    else
                    {
                        e.TargetDropItem.IsDropAllowed = false;
                    }
                }
                else
                {
                    e.TargetDropItem.IsDropAllowed = false;
                }
            }

The problem is that when we drag the last treeview item downwards, the e.dropitem is self but the visual indication is displayed below the root treeview item. On mouseup, the item is dropped as a sibiling to the root treeview item.

Drag Drop of last item (level n; n<>0) in the treeview adds it as a sibiling to level 0 items of the treeview

Please advice

Thanks
Jay

No answers yet. Maybe you can help?

Tags
DragAndDrop
Asked by
Jay
Top achievements
Rank 1
Share this question
or