0

Normally, to move a column in a DataGridView, you just click and drag. However, if you scroll immediately before this operation (which is quite common if you are moving columns), then you must click on the column before the click-and-drag. I thought this had something to do with the DataGridView losing focus, so I listened for Scroll events of type EndScroll from the horizontal scroll bar and called Focus() on the DataGridView there. That did not work. Does someone know how I can move columns without the extra click in this case?

Little Endian
  • 784
  • 8
  • 19

1 Answers1

0

This looks like a WinForms bug.

Decompiling System.Windows.Forms helped me to find the solution : declare a DataGridView child class and override the OnScroll function this way :

protected override void OnScroll(ScrollEventArgs e)
{
    base.OnScroll(e);
    base.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
}
Bioukh
  • 1,888
  • 1
  • 16
  • 27