Skip to main content

Tutorial: Column Resizing

  • 2 minutes to read

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

Default Behavior

By default, end-users can resize any grid column at runtime by dragging that column’s right edge. The same functionality is also available to you in Visual Studio.

GridView - End-User Column Resizing

Specifying Column Width

You can also access column settings via the Property grid and change the GridColumn.Width property value.

GridColumn.Width Property

Restricting End-User Capabilities

If you don’t want end-users to resize a column, toggle that column’s OptionsColumn.AllowSize option. You will see that the column’s right edge can no longer be dragged. If you want to disable column resizing for all column in the GridView, use the View’s GridOptionsCustomization.AllowColumnResizing option available under GridView.OptionsCustomization.

GridView-OptionsCustomization-AllowColumnResizing

Responding to Column Width Changes

To respond to column width changes, handle the View’s GridView.ColumnWidthChanged event. The sample code in our example first checks if the resized column is “Unit Price”. Then, it sets column text formatting and uses the column’s new width to specify whether to display or hide decimal places.

private void gridView1_ColumnWidthChanged(object sender, DevExpress.XtraGrid.Views.Base.ColumnEventArgs e) {
   if (e.Column != colUnitPrice) return;
      colUnitPrice.DisplayFormat.FormatString = (colUnitPrice.Width > 50) ? "c2" : "c0";
}

Run the app and resize the column to see that code works as expected.

GridView_RespondToWidthChanges

See Also