Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5932623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:51:36+00:00 2026-05-22T14:51:36+00:00

Winforms TreeView, I want to scroll up/down when the user drag and item.

  • 0

Winforms TreeView, I want to scroll up/down when the user drag and item.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T14:51:36+00:00Added an answer on May 22, 2026 at 2:51 pm

    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:

    // Make sure you have the correct using clause to see DllImport:
    // using System.Runtime.InteropServices;
     [DllImport("user32.dll")]
        private static extern int SendMessage (IntPtr hWnd, int wMsg, int wParam, 
            int lParam);
    

    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.

    // 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 void DragScroll (
        object sender,
        DragEventArgs e)
    {
        // Set a constant to define the autoscroll region
        const Single scrollRegion = 20;
    
        // See where the cursor is
        Point pt =  TreeView1.PointToClient(Cursor.Position);
    
        // See if we need to scroll up or down
        if ((pt.Y + scrollRegion) > TreeView1.Height)
        {
            // Call the API to scroll down
            SendMessage(TreeView1.Handle, (int)277, (int)1, 0);
        }
        else if (pt.Y < (TreeView1.Top + scrollRegion))
        {
            // Call thje API to scroll up
            SendMessage(TreeView1.Handle, (int)277, (int)0, 0);
    }
    

    Taken from here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a treeview (winforms) which have different item types on it. I have
I have a WinForms control inherited from TreeView and I want it to automatically
I create a treeview with several nodes in a WinForms application. I want to
I have a TreeView in my Windows Form user interface. I want to fill
I want to make in a TreeView (winforms) that each node will have in
I have a WinForms TreeView with one main node and several sub-nodes. How can
I have a winforms TreeView control that allows you to browse an object hierarchy.
Is there an easy way to add nodes to a WinForms .NET TreeView control
I have a TreeView control in my WinForms .NET application that has multiple levels
I have a TreeView control in a Winforms app, and basically the objective is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.