Cancelling expanding of a node on drop

2 posts, 0 answers
  1. j0rge
    j0rge avatar
    7 posts
    Member since:
    May 2007

    Posted 06 Sep 2007 Link to this post

    Hi,
    I would like to stop a node expanding while the mouse is hoovering a node while draging another node.

    I've tried the following:

    On my class which inherits from RadTreeNode:

    public override void Expand()
    {
    // stop node expanding if dropping to it
    if (this.TreeView.DraggedNode!=null || (this.TreeView.SelectedNode!=null && this.TreeView.SelectedNode!=this))
    return;
    ...

    The problem here is that the node will not expand if it is not selected, which is the case if i click on the expand icon which does not select the node.

    private void deviceTree_Expanding(object sender, System.ComponentModel.CancelEventArgs e)
    {
    // I set the dragNode variable on the Dragging event of the treeview
    if (dragNode != null)
    e.Cancel = true;
    }

    The problem with this solution is that the event is triggered after Expand method of the node.

    How can I accomplish this? my problem is that many nodes have large quantities of children and the tree is quite sensitive to which node to drop to, one has to move the mouse a little to choose the right node.

    root
    + node1
    + node2
    + node3
    + node4

    if I want to drop node4 on node2 it requires the user to move the mouse carefully, it could end up on node1,  node2 or node3, but then node1 expands and i have to cancel the drop and start all over again. Is there a way to change this behaviour? that is expand while dropping OR at least increase the "onhoover" time before expanding.

    Thanks,
    / jorge

  2. Boyko Markov
    Admin
    Boyko Markov avatar
    610 posts

    Posted 07 Sep 2007 Link to this post

    Hi j0rge,

    We do not have a built-in mechanism which will stop the auto-node expand feature while dragging a node, but using the flexible API of RadTreeView this effect could be very easily achieved only with a few lines of code. The solution is to subscribe for the following events - DragStarted, DragEnded and NodeExpandedChanged. Then in the DragStarted and DragEnded events change the value of a boolean variable which to use as a flag to point whether we are dragging the node (lets call it dragging). After that place the code snippet below in the NodeExpandedChanged event handler:
     
    if (dragging)  
                {  
                    if ( e.Node.Expanded )  
                        e.Node.Collapse();  
                } 

    Thus your nodes will be expanded on drag and drop but just after that they will be collapsed back.

    We will consider adding support for this feature for the upcoming major release of RadControls for WinForms. If you need further information please feel free to write us back.
     

    Best wishes,
    Ray
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top