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

[Solved] Question on Drop/Drag Root Level

4 Answers 162 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
jbaird
Top achievements
Rank 1
jbaird asked on 07 Jul 2009, 12:48 PM
We have the following example:

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

Sort by
0
Kiril Stanoev
Telerik team
answered on 07 Jul 2009, 02:45 PM
Hello John,

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.
0
jbaird
Top achievements
Rank 1
answered on 07 Jul 2009, 03:23 PM
We tried what you've shown.  The issue is we need to allow dragging of children items whereever under a root or accross roots.  However, we want to disallow dragging a root item into the child container.
0
jbaird
Top achievements
Rank 1
answered on 07 Jul 2009, 06:50 PM

 

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

 

Shuming Zhang

Application Development

0
Miroslav
Telerik team
answered on 13 Jul 2009, 01:50 PM

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,

Miroslav
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.
Tags
TreeView
Asked by
jbaird
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
jbaird
Top achievements
Rank 1
Miroslav
Telerik team
Share this question
or