Question How to click and drag columns in a DataGridView outside current displayed region

Rob Sherratt

Well-known member
Dec 30, 2012
Corfu. Greece
Programming Experience
My Windows Forms application uses a DataGridView with over 100 columns. The app was developed in VB with Visual Studio 2012. I have set:

MyDataGridView.AllowUserToOrderColumns = True

There are also horizontal and vertical scroll bars. The ability (provided by Microsoft) for a user to click and hold a column header and "drag" the column to a new column position in the current display region is useful.

BUT, if the user wants to "move" the column to a position that is "off screen", there is no behaviour as standard to automatically adjust the scrollbar and move left or right of the currently displayed region.
What I need is a mechanism to detect when the "dragged" column moves to the left or right of the currently displayed region, then slide the scroll region automatically to the left or right as appropriate, updating the scroll bar
And of course the currently selected "mouse down" column being "dragged" must remain selected after any code to move the display region left or right has run.

Can anyone help me with this please?

Many thanks,
Top Bottom