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 822489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:48:22+00:00 2026-05-15T02:48:22+00:00

Can anyone please suggest how should I implement column drag and drop (with auto

  • 0

Can anyone please suggest how should I implement column drag and drop (with auto scroll) feature in DataGridView. I know I can use the controll’s AllowUserToDragDrop option. However, since my datagridview control has relatively large number of columns, I need an auto scroll feature which follows the current drag-drop position so that users can see the destination column(s) before dropping. I have implemented the custom drag and drop feature but still I am having problem to enable auto scroll option.

  • 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-15T02:48:22+00:00Added an answer on May 15, 2026 at 2:48 am

    I am using the following class to auto-scroll a TTreeView. The TScroller is created in the Create of the Frame on which it sits, passing in the TreeView. It is destroyed in the frame’s Destroy. In the OnDragOver of the TreeView I simply call MyDragScroller.Scroll(State);

    type
      TScroller = class(TObject)
      private
        MyTimer: TTimer;
        FControl: TWinControl;
        FSensitiveSize: Integer;
      protected
        procedure HandleTimer(Sender: TObject);
      public
        constructor Create(aControl: TWinControl);
        destructor Destroy; override;
    
        procedure Scroll(const aState: TDragState);
      end;
    
    implementation
    
    { TScroller }
    
    constructor TScroller.Create(aControl: TWinControl);
    begin
      inherited Create;
      MyTimer := TTimer.Create(nil);
      MyTimer.Enabled := False;
      MyTimer.Interval := 20; // Not too short, otherwise scrolling flashes by.
      MyTimer.OnTimer := HandleTimer;
    
      FControl := aControl;
      // Width/Height from edge of FControl within which the mouse has to be for
      // automatic scrolling to occur. By default it is the width of a vertical scrollbar.
      FSensitiveSize := GetSystemMetrics(SM_CXVSCROLL);
    end;
    
    destructor TScroller.Destroy;
    begin
      FreeAndNil(MyTimer);
      FControl := nil;
      inherited;
    end;
    
    procedure TScroller.HandleTimer(Sender: TObject);
    var
      MousePos: TPoint;
      MouseX: Integer;
      MouseY: Integer;
    
      function _MouseInSensitiveSize: Boolean;
      begin
    
        MousePos := FControl.ScreenToClient(Mouse.CursorPos);
        MouseY := MousePos.Y;
        MouseX := MousePos.X;
    
        Result :=
             ((MouseY >= 0) and (MouseY < FSensitiveSize))
          or ((MouseY > FControl.ClientHeight - FSensitiveSize) and (MouseY <= FControl.ClientHeight))
          or ((MouseX >= 0) and (MouseX < FSensitiveSize))
          or ((MouseX > FControl.ClientWidth - FSensitiveSize) and (MouseX <= FControl.ClientWidth))
        ;
    
      end;
    begin
      if Mouse.IsDragging and _MouseInSensitiveSize then begin
        if MouseY < FSensitiveSize then begin
          FControl.Perform(WM_VSCROLL, SB_LINEUP, 0);
        end else if MouseY > FControl.ClientHeight - FSensitiveSize then begin
          FControl.Perform(WM_VSCROLL, SB_LINEDOWN, 0);
        end;
    
        if MouseX < FSensitiveSize then begin
          FControl.Perform(WM_HSCROLL, SB_LINELEFT, 0);
        end else if MouseX > FControl.ClientWidth - FSensitiveSize then begin
          FControl.Perform(WM_HSCROLL, SB_LINERIGHT, 0);
        end;
      end else begin
        MyTimer.Enabled := False;
      end;
    end;
    
    procedure TScroller.Scroll(const aState: TDragState);
    begin
      if not Mouse.IsDragging then Exit;  // Only scroll while dragging.
      if not (aState in [dsDragMove]) then Exit; // No use scrolling on a dsDragLeave and not nice to do so on a dsDragEnter.
    
      MyTimer.Enabled := True;
    end;
    

    Notes:
    If you have more controls that need auto-scrolling, you would need to create a TScroller per control. In that case it would probably do the performance of your app a lot of good to use some sort of observer/observed mechanism to share a timer between all scrolling controls.

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

Sidebar

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.