Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
UltraWinTree Scrollbar can't be scrolled
posted

I am implementing a drag and drop hierarchy builder in our application using the UltraWinTree.  I used your online code examples to determine how to implement the drag and drop of nodes.  This seems to be working as I would want it to.  However, when I try to grab the scroll bar after moving nodes around I am unable to leaving the scroll wheel on the mouse as the only way to scroll up and down in the tree.

My code is based on your sample code but does have some minor changes to support dragging multiple nodes from the source tree.  This works fine for moving the nodes.  Here's my code; I hope someone can tell me why the scroll bar won't work.

        private void m_Tree_DragDrop(object sender, DragEventArgs e)
        {
            UltraTree destinationTree = sender as UltraTree;

            //    Get the cursor position (as relative to the control's coordinate
            //    system) and determine whether there is a node under it.
            Point cursorPos = destinationTree.PointToClient(new Point(e.X, e.Y));
            UltraTreeNode destinationNode = destinationTree.GetNodeFromPoint(cursorPos);

            object dragData = e.Data.GetData(typeof(UltraTreeNode)) as UltraTreeNode;

            if (dragData == null)
                dragData = e.Data.GetData(typeof(SelectedNodesCollection)) as SelectedNodesCollection;

            TreeNodesCollection nodesTarget = null;

            if (destinationNode != null)
            {
                if (dragData != null)
                {
                    //    This is not necessary to complete the drag, but most of
                    //    the time the end user will want to begin working with
                    //    the tree that received the drop.
                    destinationTree.Select();
                    destinationTree.ActiveNode = destinationNode;

                    nodesTarget = destinationNode.Nodes;

                    //    If the Control key is pressed, clone the drag node (and any
                    //    descendant nodes) and add them to the destination node's
                    //    Nodes collection. If the Control key is not pressed, use
                    //    the Reposition method, which removes the nodes from the source
                    //    collection and adds them to the destination Nodes collection.
                    //if ((e.KeyState & KEYSTATE_CONTROL) == KEYSTATE_CONTROL)
                    //{
                    //    UltraTreeNode dragNodeClone = dragNode.Clone() as UltraTreeNode;
                    //    destinationNode.Nodes.Add(dragNodeClone);
                    //}
                    //else
                }
            }
            else if (dragData != null)
            {
                nodesTarget = destinationTree.Nodes;
            }

            if (nodesTarget != null)
            {
                if (dragData is UltraTreeNode)
                    ((UltraTreeNode)dragData).Reposition(nodesTarget);
                else if (dragData is SelectedNodesCollection)
                {
                    SelectedNodesCollection nodes = (SelectedNodesCollection)dragData;

                    for (int n = nodes.Count - 1; n >= 0; --n)
                    {
                        nodes[n].Reposition(nodesTarget);
                    }
                }
            }
        }

        private void m_Tree_DragOver(object sender, DragEventArgs e)
        {
            UltraTree destinationTree = sender as UltraTree;

            //    Get the cursor position (as relative to the control's coordinate
            //    system) and determine whether there is a node under it.
            Point cursorPos = destinationTree.PointToClient(new Point(e.X, e.Y));
            UltraTreeNode nodeAtPoint = destinationTree.GetNodeFromPoint(cursorPos);

            //    If there is no node under the cursor, show the "no drop" cursor
            if (nodeAtPoint == null)
                e.Effect = DragDropEffects.Move;
            else
            {
                //    If there is a node under the cursor, show either the 'Move'
                //    or 'Copy' cursor, based on whether the Control key is pressed
                e.Effect =  DragDropEffects.Move; *(e.KeyState & KEYSTATE_CONTROL) == KEYSTATE_CONTROL ? DragDropEffects.Copy :*/

                //    Select the node under the cursor, to provide a visual
                //    cue as to what node will receive the drop operation,
                //    and refresh the display so the selection is shown immediately.
                nodeAtPoint.Selected = true;
                destinationTree.Refresh();
            }
        }

        private void m_Tree_MouseDown(object sender, MouseEventArgs e)
        {
            this.lastMouseDownPoint = new Point(e.X, e.Y);
        }

        private void m_Tree_MouseMove(object sender, MouseEventArgs e)
        {
            UltraTree sourceTree = sender as UltraTree;

            //    We are only interested in this event when the left
            //    mouse button is pressed
            if (e.Button == MouseButtons.Left)
            {
                //    Get the cursor position (as relative to the control's coordinate
                //    system) and determine whether it is within the drag threshold
                Point cursorPos = new Point(e.X, e.Y);

                Rectangle dragRect = new Rectangle(this.lastMouseDownPoint, SystemInformation.DragSize);
                dragRect.X -= SystemInformation.DragSize.Width / 2;
                dragRect.Y -= SystemInformation.DragSize.Height / 2;

                //    If it is within the drag threshold, initiate the drag/drop operation,
                //    specifying the ActiveNode as the "drag node"
                if (dragRect.Contains(cursorPos))
                    sourceTree.DoDragDrop(sourceTree.ActiveNode, DragDropEffects.All);
            }
        }