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 System.Windows.Forms.DataGridView.AllowUserToOrderColumns property value determines whether users can move columns to different positions.

There is support for this task in Visual Studio. How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer
How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer
How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer
How to: Enable Column Reordering in the Windows Forms DataGridView Control Using the Designer

To enable column reordering programmatically

  • Set the System.Windows.Forms.DataGridView.AllowUserToOrderColumns property to true.

    dataGridView1.AllowUserToOrderColumns = True
    
    dataGridView1.AllowUserToOrderColumns = true;
    

Compiling the Code

This example requires:

See Also

Tasks

How to: Freeze Columns in the Windows Forms DataGridView Control

Reference

DataGridView
System.Windows.Forms.DataGridView.AllowUserToOrderColumns

Other Resources

Basic Column, Row, and Cell Features in the Windows Forms DataGridView Control