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

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

6 Answers 195 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 17 Sep 2011, 07:11 PM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 21 Sep 2011, 05:06 PM
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 >>

0
Anders
Top achievements
Rank 1
answered on 03 Oct 2011, 08:12 AM
Thank you - it works like a charm!
0
Robert
Top achievements
Rank 1
answered on 05 Apr 2012, 12:34 AM
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.
0
Robert
Top achievements
Rank 1
answered on 05 Apr 2012, 01:41 AM
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.
0
Robert
Top achievements
Rank 1
answered on 05 Apr 2012, 02:00 AM
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;
            }
        }

0
Tina Stancheva
Telerik team
answered on 09 Apr 2012, 07:55 AM
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 >>

Tags
TreeView
Asked by
Anders
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Anders
Top achievements
Rank 1
Robert
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or