How to: Enable Column Reordering in the Windows Forms DataGridView Control
When you enable column reordering in the DataGridView control, users can move a column to a new position by dragging the column header with the mouse. In the DataGridView control, the DataGridView.AllowUserToOrderColumns property value determines whether users can move columns to different positions.
There is support for this task in Visual Studio. For more information, see How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer and How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer and How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer and How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer.
To enable column reordering programmatically
Set the DataGridView.AllowUserToOrderColumns property to true.
dataGridView1.AllowUserToOrderColumns = True
dataGridView1.AllowUserToOrderColumns = true;
Compiling the Code
This example requires:
A DataGridView control named dataGridView1.
References to the System and System.Windows.Forms assemblies.
See Also
Tasks
How to: Freeze Columns in the Windows Forms DataGridView Control
Reference
DataGridView.AllowUserToOrderColumns
Other Resources
Basic Column, Row, and Cell Features in the Windows Forms DataGridView Control