Accessing DropPosition in OnDropQuery (Drag'n'drop)?

7 posts, 1 answers
  1. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 17 Sep 2011 Link to this post

    Hi Telerik,

    I can't seem to find the DropPosition when determining wheter a drop is allowed? Am I overlooking something? I can see the relative position and I guess I could calculate the relative position, but since the curson changes depending on drop position, I'm thinking the information is there somewhere...

    Thnaks for any help,

    Anders, Denmark
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 21 Sep 2011 Link to this post

    Hello Anders,

     You can first access the destination ( TreeViewItem  or TreeView) and get the position like so:

    var item = e.Options.Destination as RadTreeViewItem;
                if (item.DropPosition != DropPosition.Inside)
                    e.QueryResult = false;
    Please let us know if this helps you or not. All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Anders
    Anders avatar
    80 posts
    Member since:
    Dec 2010

    Posted 03 Oct 2011 Link to this post

    Thank you - it works like a charm!
  5. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 04 Apr 2012 Link to this post

    Hi,

    The sample you gave is the same as the documentation and it works well.
    However, how can I stop a "Group" node from being dropped inside another "Group" node?

    Thank you for your time.
  6. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 04 Apr 2012 Link to this post

    Ok, well I worked this out:

    private void OnDropInsideTreeViewDropQuery(object sender, DragDropQueryEventArgs e)
    {
    //Drop Destination
    var treeViewItem = e.Options.Destination as RadTreeViewItem;
    //Node being dragged
    object selectedTreeItem = ((RadTreeViewItem)e.OriginalSource).Item;
    //Check if node being dragged is top node
    if (selectedTreeItem is ParksGroupDataStruct)
    {
    e.QueryResult = false;
    }
    //If not top node being dragged then only allow drop inside
    else if (treeViewItem.DropPosition != DropPosition.Inside)
    {
    e.QueryResult = false;
    }
    }


    Not sure if this is the best way to do it, but it works. If there's any better advice then I'm all ears (or eyes in this case).

    Now I need to figure out the null exception being thrown if item is being dragged into white space of TreeView.
  7. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 04 Apr 2012 Link to this post

    Here's the code to disable drop in white space to cancel out the null exception thrown.

    private void OnDropInsideTreeViewDropQuery(object sender, DragDropQueryEventArgs e)
            {
                //Drop Destination
                var destinationTreeViewItem = e.Options.Destination as RadTreeViewItem;
                //Node being dragged
                object selectedTreeItem = ((RadTreeViewItem)e.OriginalSource).Item;
     
                //Check drop destination isn't null (white space)
                if (destinationTreeViewItem == null)
                {
                    e.QueryResult = false;
                }
                //Check if node being dragged is top node
                else if (selectedTreeItem is ParksGroupDataStruct)
                {
                    e.QueryResult = false;
                }
                //If not top node being dragged then only allow drop inside
                else if (destinationTreeViewItem.DropPosition != DropPosition.Inside)
                {
                    e.QueryResult = false;
                }
            }

  8. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 09 Apr 2012 Link to this post

    Hi Robert,

    I am glad you found a solution for your scenario. Handling the OnDropQuery event is the right approach for your case, but should you encounter any issues with it or you need our assistance, please let us know.

    Regards,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WPF is Visual Studio 2017 Ready