Nodes order after Drag&Drop

2 posts, 0 answers
  1. Thomas
    Thomas avatar
    22 posts
    Member since:
    Oct 2012

    Posted 08 Oct 2014 Link to this post

    Hi,

    I have trouble with node dragging. It can be reproduced in your demo "Demo Application - Telerik UI for WinForms Q2 2014 SP1". Select "Tree View" -> "Drag & Drop". I am using left tree.
    1. Click on the node "Drafts";
    2. Press shift button and click on the "Outbox" node;
    3. Release shift button;
    4. Press left mouse button on the "Outbox" node and start dragging;
    5. Drop selected nodes after node "Large Mail".

    You can see that order of nodes was changed.
    Before: "Drafts", "Inbox" and "Outbox"
    After: "Outbox", "Drafts" and "Inbox"

    How I can change this behavior?
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 13 Oct 2014 Link to this post

    Hello Thomas,

    Thank you for writing.

    I confirm that the selected nodes order is incorrect when performing the described steps. I have logged it in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item.

    I have also updated your Telerik points.

    Currently, the possible solution that I can suggest is to perform manually the selection in the desired order. Here is a sample implementation:
    RadTreeNode startNode = null;
    RadTreeNode endNode = null;
    List<RadTreeNode> selectedNodes;
    bool performSelection = false;
    bool reverse = false;
     
    private void radTreeView1_SelectedNodeChanging(object sender, RadTreeViewCancelEventArgs e)
    {
        if (Control.ModifierKeys == Keys.Shift &&
            e.TreeView.SelectedNodes.Count == 1 &&
            e.Node != e.TreeView.SelectedNodes.First())
        {
            endNode = e.Node;
            startNode = e.TreeView.SelectedNodes.First();
        }
    }
     
    private void radTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        if (e.TreeView.SelectedNodes.Count >= 2 &&
            e.TreeView.SelectedNodes.First() == endNode &&
            e.TreeView.SelectedNodes[1] == startNode &&
            !performSelection)
        {
            performSelection = true;
            reverse = false;
            selectedNodes = new List<RadTreeNode>();
          
            for (int i = 1; i < e.TreeView.SelectedNodes.Count; i++)
            {
                selectedNodes.Add(e.TreeView.SelectedNodes[i]);
            }
            if (startNode.Level > 0 && startNode.Level == endNode.Level)
            {
                if (startNode.Parent == endNode.Parent)
                {
                    if (startNode.Parent.Nodes.IndexOf(startNode.Text) > startNode.Parent.Nodes.IndexOf(endNode.Text))
                    {
                        reverse = true;
                        selectedNodes.Reverse();
                    }
                }
            }
            else if (e.TreeView.Nodes.IndexOf(startNode.Text) > e.TreeView.Nodes.IndexOf(endNode.Text))
            {
                reverse = true;
                selectedNodes.Reverse();
            }
            
            e.TreeView.SelectedNodes.Clear();
            if (reverse)
            {
                if (endNode.Parent != null)
                {
                    e.TreeView.Nodes[endNode.Parent.Text].Nodes[endNode.Text].Selected = true;
                }
                else
                {
                    e.TreeView.Nodes[endNode.Text].Selected = true;
                }
            }
            foreach (RadTreeNode n in selectedNodes)
            {
                n.Selected = true;
            }
            if (!reverse)
            {
                if (endNode.Parent != null)
                {
                    e.TreeView.Nodes[endNode.Parent.Text].Nodes[endNode.Text].Selected = true;
                }
                else
                {
                    e.TreeView.Nodes[endNode.Text].Selected = true;
                }
            }
             
            performSelection = false;
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.
     
    Regards,
    Desislava
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top