How to turn off drop between nodes on a RadTreeView

11 posts, 0 answers
  1. Shahveer
    Shahveer avatar
    2 posts
    Member since:
    Jul 2011

    Posted 07 Sep 2011 Link to this post

    Hello,

    I have been searching for a way to do this for a couple of days now, does anyone know if there is a way to turn off droping between nodes when doing drag and drop on a radTreeView, in my case there are parent nodes already created and all the nodes that will be dragged in have to go in one of these parent nodes, i cant allow them to place a node between two of the parent nodes.

    Thanks
  2. Ivan Ivanov
    Admin
    Ivan Ivanov avatar
    1128 posts

    Posted 09 Sep 2011 Link to this post

    Hi Shahveer,

    Would you please shed some more light on your requirements, in order to help us give you proper guidelines? Well, you have a RadTreeView with two parent nodes and you are dropping additional nodes in. You want to prevent the new nodes from going on one an the same level with the parent nodes, am I right? Do you expect the new nodes to be draggable once after they have been dropped in the RadTreeView? Where do you get the dragged nodes from?

    Regards,
    Ivan Ivanov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 20 Sep 2011 Link to this post

    Hi Ivan,
    i have the same problem. I have a RadTreeView and on the dragover event i check if the item can drop into this parent. If not allowed then i set the dropeffects to DragDropEffects.None, else DragDropEffects.Copy. That works fine. The cursor is on a Parent the "copycursor" and on a Parent.Parent the "notallowed" cursor, perfect! BUT between a parent.parent and an other parent.parent the cursor switches to "copycursor". So the user could think he can drop, that is wrong.

    I can turn off this, if i call the dodragdrop methode with allowed effects == None, but then i never get the "copycursor". My dodragdrop methode looks currently like this:
    System.Windows.DragDrop.DoDragDrop(_treeView, dataObject, DragDropEffects.None| DragDropEffects.Copy);

    Whats wrong or what can i do that the cursor is only "copycursor" on the allowed parents and not between not allowed parents?

    Thanks
    Annett
  5. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 23 Sep 2011 Link to this post

    Hi,

    has anyone an idea?
    _radTreeView.HideBetweenItemsDragCue() doesn't work.
    Property EnableDragAndDropBetweenNodes doesn't exist in Telerik.Windows.Controls.Navigation.

    Annett
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 26 Sep 2011 Link to this post

    Hello Annett,

     Could you please send us a captured video of what you are trying to achieve ? Any sample code would also be highly appreciated since this way we would be better able to investigate this and provide you a solution or advice. Thank you for your cooperation. 

    Regards,
    Petar Mladenov
    the Telerik team

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

  7. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 28 Sep 2011 Link to this post

    Hello Petar,

    i copied the code from the Drop and Drag Manager. I will create a video, i put todays evening the video to the net an post the link.
    Here the code:

    DragManager

            /// <summary>
            /// Starts the drag operation.
            /// </summary>
            private void StartDrag()
            {
                if (_treeView != null)
                {
                    IsDragging = true;

                    var ctx = _treeView.DataContext as ContextViewModel;
                    if (ctx != null)
                    {
                        var dataObject = ctx.SelectedItemsDataObject;
                        {
                            if (dataObject != null)
                            {
                                System.Windows.DragDrop.DoDragDrop(
                                    _treeView, dataObject, DragDropEffects.Copy);
                            }
                        }
                    }
                    IsDragging = false;
                }
            }
      
      
    DropManager

            private void TreeViewDragOver(object sender, DragEventArgs e)
            {
                if (e.OriginalSource != null && typeof(TextBlock).IsInstanceOfType(e.OriginalSource))
                {
                    RadTreeViewItem tvi = GetTreeViewItemFromChild(e.OriginalSource as DependencyObject);
                    if (tvi != null)
                    {
                        var item = tvi.Header;
                        DragItem = item;
                    }

                    SetDragDropEffects(e);
                    e.Handled = true;
                }
            }

            private void SetDragDropEffects(DragEventArgs e)
            {
                e.Effects = DragDropEffects.None;
               
                if (e.Data.GetDataPresent(typeof(AddressRepresentation[]).FullName))
                {
                    if(_dragManager.IsDragging)
                    {
                        if (_treeView.ContextViewModel.CanDrop(DragItem, e.Data.GetData(typeof(AddressRepresentation[]).FullName, true) as AddressRepresentation[]))
                        {
                            e.Effects = DragDropEffects.Copy;
                        }
                    }
                }
            }

      static RadTreeViewItem GetTreeViewItemFromChild(DependencyObject child)
            {
                if (child != null)
                {
                    if (child is RadTreeViewItem)
                    {
                        return child as RadTreeViewItem;
                    }
                    else if (child is TreeView)
                    {
                        return null; //we've walked through the tree. The source of the click is not something else
                    }
                    else
                    {
                        DependencyObject par = null;
                        if (child is Visual || child is System.Windows.Media.Media3D.Visual3D)
                            par = VisualTreeHelper.GetParent(child);
                        else
                            par = LogicalTreeHelper.GetParent(child);

                        return GetTreeViewItemFromChild(par);
                    }
                }
                return null;
            }


  8. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 29 Sep 2011 Link to this post

    Hi,

    the video you can see under: http://www.annett-tempel.de/videos/dragtest.swf

    The item "L.01 Lampe" can dropped only in "01 Gruppe". If i drag over Gruppe i have a
    copycursor if a drag over Anlage or System i have a nonecursor. Thats ok. But if i drag between System and Anlage i
    have a copycursor. This cursor is wrong. it must be a nonecursor. I dont know how i can i turn off the
    copycursor between items.

    Hope now its clear what my problem is.
    Annett
  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Sep 2011 Link to this post

    Hello Annett,

     I prepared a project for you where I used the RadDragAndDropManager.DragQuery event. In its handler I check the type of the target Item and set e.QueryResult = false if I want to disable the drop operation.You can test it like so: drag a file over a Folder with Name Starting with "Folder" and see that the drop is disabled. Please check out this solution and let us know if it could fit in your scenario. 

    Kind regards,
    Petar Mladenov
    the Telerik team

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

  10. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 05 Oct 2011 Link to this post

    Hello Petar,

    i checked this out. The e.Options.Destination is always NULL. I think this could be the problem. Have i forgotten something? What must i do that destination is not null?

    Annett
  11. Annett
    Annett avatar
    24 posts
    Member since:
    Sep 2011

    Posted 05 Oct 2011 Link to this post

    It's very odd. Only if i have make a drop somewhere, the destination property is not null with the second try. But even if i set always e.QueryResult = false the cursor switches to "can copy" like in my video. :-(
  12. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 10 Oct 2011 Link to this post

    Hello Annett,

    Is it possible for you to send us an isolated sample showing the problem? This way we would be better able to investigate this and configure the RadDragAndDropManager events in the right way. Thank you for your cooperation in advance. 

    All the best,
    Petar Mladenov
    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