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

1 posts, 0 answers
  1. Jay
    Jay avatar
    5 posts
    Member since:
    Mar 2012

    Posted 25 May 2012 Link to this post

    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
Back to Top