Multimobile Development: Building Applications for any Smartphone
Dragdrop and scrolling
Messages   Related Types
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.
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
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.
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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
Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
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.
Reply to this message...
Vote that this is a GOOD answer...
 
First chapters of Multimobile Development book now available on Apress Alpha program
iPad
 
    
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]

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
David Regan
Fair enough---it's remarkable how complete .NET is already. I was just
concerned that I wasn't missing something fundamental.
Reply to this message...
Vote that this is a GOOD answer...
 
New book project – Multimobile Development: Building Applications for any Smartphone
Dive into HTML5
 
    
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
Reply to this message...
Vote that this is a GOOD answer...
 
Steve Jobs’ thoughtful/thought provoking Thoughts on Flash…
Handy list of countries in CSV format
 
 
System.EventArgs
System.Int32
System.IntPtr
System.UInt32
System.Web.UI.Control
System.Windows.Forms.Cursor
System.Windows.Forms.DragEventArgs
System.Windows.Forms.ScrollEventArgs
System.Windows.Forms.TreeNode
System.Windows.Forms.TreeView




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734