Skip to main content

Tutorial: Column Reordering

  • 2 minutes to read

This walkthrough is a transcript of the Column Reordering video available on the DevExpress YouTube Channel.

Default Behavior

By default, the GridView allows end-users to reorder columns by simply dragging their headers. The same drag-and-drop functionality is available to you in the Visual Studio designer.

GridView_EndUserReordering

Specifying Column Position

You can also specify a column’s position using its GridColumn.VisibleIndex property.

GridView_VisibleIndexProperty

Restricting End-User Capabilities

Header drag and drop is enabled for all columns by default. To disable it for a particular column, use the OptionsColumn.AllowMove option. Note though that this column’s position can change if you move other columns. If you want to completely disable column reorder within the view, use the View’s GridOptionsCustomization.AllowColumnMoving option available under GridView.OptionsCustomization.

GridView_AllowColumnMovingProperty

Responding to Column Order Changes

If you need to respond to column order changes at runtime, handle the View’s ColumnView.ColumnPositionChanged event. In the handler, identify the column that was moved using the Sender parameter. Then, display the caption of that column and the Category‘s column index.

private void gridView1_ColumnPositionChanged(object sender, EventArgs e) {
    GridColumn column = sender as GridColumn;
    statusBarText.Caption = string.Format("You've moved the \"{0}\" column. \"Category\" column index is: {1}",
        column.GetCaption(), colCategory.VisibleIndex);
}

Run the application and move one of the columns. Notice the Category column’s position displayed in the status bar.

GridView_ColumnPositionChangedResult

Now move a column over Category. You’ll now see how one column reordering operation can actually affect other columns.

See Also