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

RadTreeView - Disable Dropping in Root Node

5 Answers 289 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Lee
Top achievements
Rank 1
Lee asked on 08 Dec 2009, 10:38 PM

EXAMPLE TREE:

ROOT
    -A
        -A1
        -A2
    -B
    -C
        -C1
        -C2
            -C2A
            -C2B
        -C3
    -D


Using the example tree above, my overall goal is to only allow nodes to be dropped within their own parent node, or essentially to be re-arranged with the node's siblings. (For example: If the user is dragging node C1, it is only to be able to be dropped BEFORE C3 or AFTER C3, no where else or in any other nodes period. Likewise, if dragging node A2, it is only to be able to be dropped BEFORE A1)


I discovered how to accomplish this by handling the PreviewDragEnded event and determining the level of the targetItem and setting eventArgs.Handled = true if the drop is invalid. I am not real high on this solution though as it appears to the user that they are able to drop the node somewhere and then nothing happens.

Instead, I would like to do something like handle the PreviewDragStarted event, Set 'IsDropAllowed = false' for all nodes of the tree, then determine the parent of the node being dragged and set 'IsDropAllowed = true' for that parent node. This way the user see's the 'stop sign, not allowed icon' for all other droppable places except within the node's parent node. (at the same level as the node being dragged) So the user knows before dropping the node that the only place it can be dropped is at it's current level of the tree.

I have spent a few hours attempting this and have constructed a simple test project that has a tree view bound to an ObservableCollection in a view model that matches the above structure. I have the PreviewDragStarted Handler rigged up to set 'IsDropAllowed = false' for all nodes of the tree, and then set 'IsDropAllowed = true' for the node being dragged's parent node. This appears to be working, as far as showing the stop sign correctly.

My problem is...

A) I cannot figure out how to set 'IsDropAllowed = false' for the Root's container. (I do this for all other nodes of the tree by getting the RadTreeViewItem of the bound item and setting the property to false. Is there a way to get a container like 'RadTreeViewItem' for the root node and set the 'IsDropAllowed' to false?) Essentially, using the above example, when dragging node C1, I can correctly only drop it within node C, but I can also drop it BEFORE/AFTER node A, BEFORE node B, AFTER node D. This is the problem.

B) When dragging a node, it makes a duplicate node at the drop location and doesnt remove the original node, any idea why this could be happening? the only thing I am doing is setting 'IsDropAllowed' property in this PreviewDragStart handler...

Thanks a bunch for any help that can be provided!

- Lee

5 Answers, 1 is accepted

Sort by
0
Lee
Top achievements
Rank 1
answered on 08 Dec 2009, 10:41 PM

I posted a support ticket for this issue as well so I could provide my stripped down test project.

My support ticket number is : 265191


Thanks again for any help that can be given!
0
hwsoderlund
Top achievements
Rank 1
answered on 10 Dec 2009, 03:39 PM
As I am also interested in the solution to this, I would very much appreciate it if any replies were posted here and not only in Lees support ticket. Thank you, /Henrik
0
Miroslav
Telerik team
answered on 11 Dec 2009, 02:53 PM
Hello Henrik,

 I replied to Lee.

In short this can happen by handling the DropQuery event, here is my reply to Lee and the attached project:
------

The TreeView uses the RadDragDropManager and you can handle the DropQuery event that "asks" whether something can be dropped.

There is no need to switch the IsDropAllowed property on the items. Generally this property can be used to specify static rules, for something more complicated using these DragDrop events is recommended.

I updated your project to allow only rearranging siblings.


Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
hwsoderlund
Top achievements
Rank 1
answered on 14 Dec 2009, 09:39 AM
Ok, sounds good. My drag/drop code was written a while back, and is in bad need of refactoring. I think the DropQuery event was not available when I wrote it, so I had to do some pretty ugly hacks to achieve what I wanted. Anyway, I will give this a try. Thanks.
0
Miroslav
Telerik team
answered on 14 Dec 2009, 01:21 PM
Hello Henrik,

Yes, the DropQuery event is was introduced with the Q2 SP1 release, version 2009.2.0812 if I remember correctly.

I believe that the DragDrop events cover almost all drag-drop scenarios now (except the ones that we have not thought of :)).

You may have seen the attached project, it shows how the DragDrop can be modified for different scenarios. If you have troubles converting or implementing something, do get back to us.


Best wishes,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Lee
Top achievements
Rank 1
Answers by
Lee
Top achievements
Rank 1
hwsoderlund
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or