Winforms TreeView, I want to scroll up/down when the user drag and item.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
When you implement drag and drop in a treeview control, you need to support some type of auto-scroll functionality. For example, when you drag an item from a visible tree node, and the destination tree node is outside of the current view of the treeview, the control should automatically scroll up or down depending on the direction of the mouse.
The Windows Forms Treeview control does not include built-in functionality to accomplish this. However, it is fairly easy to implement this yourself.
Step 1: Get your treeview drag and drop code working
Make sure your treeview drag and drop code works correctly without autoscrolling. See the topics in this folder for more information on how to implement drag and drop in a treeview.
Step 2: Add a definition for the SendMessage function
In order to tell the treeview to scroll up or down, you need to call the Windows API SendMessage() function. To do this, add the following code the top of your class:
Step 3: Hook into the DragScroll Event
In the DragScroll event, determine where the mouse cursor is in relation to the top and bottom of the treeview control. Then call SendMessage to scroll as apporpriate.
Taken from here.