Root 1
Child 1
Child 2
Root 2
Child 3
Child 4
We are trying to NOT allow dropping Root2 before,after or in Child 2. We tried putting code into the PreviewDragEnded event, however the TargetDropItem is null.
We were trying to check the TargetDropItem and Level to disallow this behavior. (e.g. We wanted to see if the TargetDropItem was at the same level).
4 Answers, 1 is accepted
If I have understood you correctly, I think you should use the IsDropAllowed property.
For example, this is how the treeview might look like:
| <telerikNavigation:RadTreeView IsDragDropEnabled="True"> |
| <telerikNavigation:RadTreeViewItem Header="Root1" IsDropAllowed="False"> |
| <telerikNavigation:RadTreeViewItem Header="Child1" IsDropAllowed="False"/> |
| <telerikNavigation:RadTreeViewItem Header="Child2" IsDropAllowed="False"/> |
| </telerikNavigation:RadTreeViewItem> |
| <telerikNavigation:RadTreeViewItem Header="Root2"> |
| <telerikNavigation:RadTreeViewItem Header="Child3" /> |
| <telerikNavigation:RadTreeViewItem Header="Child4" /> |
| </telerikNavigation:RadTreeViewItem> |
| </telerikNavigation:RadTreeView> |
In the above example, Drag&Drop operations are allowed everywhere except Root1, Child1 and Child2.
Give it a try and let us know if you encounter any problems.
Greetings,
Kiril Stanoev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
We found in Telerik forum that the bug TargetDropItem being null when DropPosition is Before or After was reported and fixed in Feb release for WPF (link for the post: http://www.telerik.com/community/forums/wpf/treeview/drag-drop-problem-bug.aspx). Will this be fixed for silverlight in the coming release?
· Posted on Jan 29 (permalink)
Hi Jarek,
We tested the issue and the PreviewDragEnded event always returned null for the TargetDropItem when the item was dropped before or after the target node. We apologize for the inconvenience. This will be fixed with the next release- Q1 which is planned around the end of February. I updated your Telerik points. For now as a workaround you can use DropPosition for your needs.
Sincerely yours,
Boyan
the Telerik team
Application Development
Hi Shuming,
Sorry for the delayed reply!
The Q2 release of the TreeView uses the DragDrop manager for handling DragDrop. This allows it to easily participate in cross-control DragDrop. The old TreeView events were kept for backward compatibility, but preferably you need to handle the DropQuery event of the DragDropManager and plug in your logic there. In this handler you have the dragged items and the destination item and you can decide whether a drop should be possible or not.
Here is how this can be done:
| <nav:RadTreeView x:Name="treeView" SelectionMode="Extended" IsDragDropEnabled="True" |
| IsEditable="False" MaxHeight="550"> |
| <nav:RadTreeViewItem Header="Root 1"> |
| <nav:RadTreeViewItem Header="Child 1" /> |
| <nav:RadTreeViewItem Header="Child 2" /> |
| </nav:RadTreeViewItem> |
| <nav:RadTreeViewItem Header="Root 2"> |
| <nav:RadTreeViewItem Header="Child 1" /> |
| <nav:RadTreeViewItem Header="Child 2" /> |
| </nav:RadTreeViewItem> |
| </nav:RadTreeView> |
And the DropQuery handler, attached to a visual parent of the TreeView, the user control that contains it:
| private void OnTreeViewDropQuery(object sender, DragDropQueryEventArgs e) |
| { |
| if (e.Options.Status == DragStatus.DropDestinationQuery) |
| { |
| var draggedItems = e.Options.Payload as ICollection; |
| foreach (var draggedItem in draggedItems.Cast<RadTreeViewItem>()) |
| { |
| //Here we check wheter we are happy with the destination |
| //and the contents of the DragDrop. In this example our |
| //items are always TreeView items and we check the header. |
| if ((draggedItem.Header as String).StartsWith("root", StringComparison.InvariantCultureIgnoreCase)) |
| { |
| e.Handled = true; |
| e.QueryResult = false; |
| //This does not work yet because the method is |
| //internal. It will be public from the next internal |
| //build onwards (expected 17 July 2009). |
| var cue = e.Options.DragCue as TreeViewDragCue; |
| cue.UpdateDragTooltip(false, null, null, DropPosition.Inside); |
| } |
| } |
| } |
| } |
Please note that currently the DragCue is not customizable because the update method is internal. With the next internal build (and release) the default TreeView DragCue will be customizable so that you will not have to create a new DragCue but just call a method / set property to the current one.
Greetings,
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
