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); } }
MRG said:I believe I have this worked out. I added a check to be sure that the mouse was over a node in the Mouse Move event. This seems to have rectified my problem.
Okay. That kinda makes sense. You were starting a drag operation when the user tried to drag the scrollbar, so that was overriding the tree's normal scrollbar dragging code.
MRG said:I would gladly add a zip file with my application It is a small prototype I am using to create functional documentation and give the my users a chance the mechanics of the form before implementing it in our application. The zip file is 55Kb. I just don't know how to add an attachment to a posting.
To attach a file to your post, go to the OPTIONS tab while replying.
I believe I have this worked out. I added a check to be sure that the mouse was over a node in the Mouse Move event. This seems to have rectified my problem.
I would gladly add a zip file with my application It is a small prototype I am using to create functional documentation and give the my users a chance the mechanics of the form before implementing it in our application. The zip file is 55Kb. I just don't know how to add an attachment to a posting.
It sounds like maybe some windows messages are getting lost or the tree is left in a bad state after the drop. Is it only the scrollbar that fails to respond to the mouse or is it the entire tree? Can you select/activate or expand a node, for example?
There's not much I can do with a code snippet. Can you post a small sample that demonstrates the issue so I can play around with it and debug it?