This message was discovered on microsoft.public.dotnet.framework.windowsforms.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
| David Regan |
I have written a winforms application that uses a treeview control. The interface allows the user to drag nodes from the tree into other locations (in the same way as a user can drag files about a file system tree).
Everything works just dandy except that I can't work out how to cause the tree control to scroll up or down as the user drags over the top or bottom edge. I've noticed that one of the available dragdropeffects is Scroll but setting this as allowed make no difference.
Could somebody outline how I should go about implementing this functionality?
Much obliged,
David.
|
|
|
| |
|
| |
| |
| Lion Shi (VIP) |
I have written a winforms application that uses a treeview control. The interface allows the user to drag nodes from the tree into other locations (in the same way as a user can drag files about a file system tree).
Everything works just dandy except that I can't work out how to cause the tree control to scroll up or down as the user drags over the top or bottom edge. I've noticed that one of the available dragdropeffects is Scroll but setting this as allowed make no difference.
Could somebody outline how I should go about implementing this functionality?
Much obliged,
David.
|
|
|
| |
|
|
| |
| |
| David Regan |
Thanks for that information. I didn't think it would be trivial but not that hard!
One thing I don't understand though---I'm using the .NET System.Windows.Forms.TreeView control. Why do I have to use the interoperate services in order to get a windows event into to cause the scrolling? Isn't there a way of doing this inside the .NET framework, such as raising an appropriate event?
Regards,
David Regan
|
|
|
| |
|
|
| |
|
|
| |
| Dan Haught |
Autoscrolling in a treeview is not that difficult to implement.
Basically, you hook into the DragOver event and check the current mouse position. If it is close to the top or bottom of the treeview, call the Windows API SendMessage() function to scroll the treeview up or down. The following code should work:
' Put this in the declarations of your class Private Declare Function SendMessage _ Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As IntPtr, _ ByVal wMsg As Integer, _ ByVal wParam As Integer, _ ByVal lParam As Integer) _ As Integer
' Implement an "autoscroll" routine for drag ' and drop. If the drag cursor moves to the bottom ' or top of the treeview, call the Windows API ' SendMessage function to scroll up or down automatically. Private Sub DragScroll( _ ByVal sender As Object, _ ByVal e As DragEventArgs) _ Handles TreeView1.DragOver
' Set a constant to define the autoscroll region Const ScrollRegion As Single = 20
' See where the cursor is Dim pt As Point = TreeView1.PointToClient(Cursor.Position)
' See if we need to scroll up or down If (pt.Y + ScrollRegion) > TreeView1.Height Then
' Call the API to scroll down SendMessage(TreeView1.Handle, 277&, 1&, vbNull)
ElseIf (pt.Y) < TreeView1.Top + ScrollRegion Then
' Call thje API to scroll up SendMessage(TreeView1.Handle, 277&, 0&, vbNull)
End If
End Sub
Hope this helps, Dan Haught FMS Inc. ------------------------- Total .NET XRef: Real-time C# and VB.NET Code Cross Reference for Visual Studio .NET. Download it today at: www.fmsinc.com/dotnet
Total SQL Analyzer PRO: comprehensive analysis, documentation, and performance tips for SQL Server. Download it today at: www.fmsinc.com/products/sqlanalyzer
"David Regan" <Click here to reveal e-mail address> wrote in message news:148f01c1e13b$f31da190$9be62ecf@tkmsftngxa03... [Original message clipped]
|
|
|
| |
|
| |
| |
| David Regan |
Thanks for both the previous replies. I've got it working using the information you both provided.
I'm still puzzled why I have to use the InteroperateServices to call the Win32 SendMessage function to cause the control to scroll. Is there not a way to raise a ScrollEvent with user supplied ScrollEventArgs against the .NET tree control?
David.
|
|
|
| |
|
| |
| |
| Dan Haught |
As with version 1 of any software, there are things missing in the .Net Framework. My guess is that Microsoft will add things to the framework as developers request them. The good news is that the Interop services work pretty well in the interim.
-dan
"David Regan" <Click here to reveal e-mail address> wrote in message news:Click here to reveal e-mail address... [Original message clipped]
|
|
|
| |
|
|
| |
| |
| David Regan |
Fair enough---it's remarkable how complete .NET is already. I was just concerned that I wasn't missing something fundamental.
|
|
|
| |
|
| |
|
|
|
|
| |
| Pete Burgess |
All you have to do is when dragging over a node, make sure that the previous and next visible nodes (i.e. not hidden) are in view:
TreeNode nodeDragTo = GetNodeAt(PointToClient(Control.MousePosition));
// make sure the next visible node is in view if (nodeDragTo.NextVisibleNode != null) nodeDragTo.NextVisibleNode.EnsureVisible(); // ensure the previous visible node is in view too! if (nodeDragTo.PrevVisibleNode != null) nodeDragTo.PrevVisibleNode.EnsureVisible();
-------------------------------- From: Pete Burgess
|
|
|
| |
|
| |
|
|
|
|
|