Skip to main content
A newer version of this page is available. .

BaseColumn.Width Property

Gets or sets the column’s width. This is a dependency property.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v20.2.Core.dll

NuGet Packages: DevExpress.WindowsDesktop.Wpf.Grid.Core, DevExpress.Wpf.Grid.Core

Declaration

public GridColumnWidth Width { get; set; }

Property Value

Type Description
GridColumnWidth

A GridColumnWidth object that is a column width.

Remarks

<dxg:GridControl.Columns>
    <!-- Absolute width in pixels -->
    <dxg:GridColumn FieldName="Name" Width="150"/>
    <!-- Proportional (star) width -->
    <dxg:GridColumn FieldName="Birthday" Width="2*"/>
    <dxg:GridColumn FieldName="Visits" Width="*"/>
    <!-- Auto width -->
    <dxg:GridColumn FieldName="City" Width="Auto"/>    
</dxg:GridControl.Columns> 

The BaseColumn.Width property specifies a column’s width.

If the total column width exceeds the grid’s width, a horizontal scrollbar is displayed, allowing an end user to scroll grid columns. If you want a column (or columns) to always be displayed onscreen, regardless of scrolling, set its BaseColumn.Fixed property. For detailed information, see Fixed Columns and Bands.

Absolute Column Size

Set the BaseColumn.Width property to a value in pixels:

<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="JobTitle" Width="150"/>
    <dxg:GridColumn FieldName="FullName" Width="150"/>
    <dxg:GridColumn FieldName="BirthDate" Width="50"/>
    <dxg:GridColumn FieldName="Country" Width="100"/>
    <dxg:GridColumn FieldName="Phone" Width="100"/>
</dxg:GridControl.Columns> 

Proportional (Star) Column Size

Set the BaseColumn.Width property to a weighted proportion of available space. Available space is distributed among columns by weighted proportions similar to the “star sizing” mechanism used by the MS Data Grid.

<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="JobTitle" Width="3*"/>
    <dxg:GridColumn FieldName="FullName" Width="3*"/>
    <dxg:GridColumn FieldName="BirthDate" Width="*"/>
    <dxg:GridColumn FieldName="Country" Width="2*"/>
    <dxg:GridColumn FieldName="Phone" Width="2*"/>
</dxg:GridControl.Columns>

Note

  • The proportional sizing work only when the GridControl has a finite width.
  • The proportional sizing does not work in column bands.

Auto Column Size

Set a column’s BaseColumn.Width property to Auto to make the GridControl automatically recalculate the optimal width for this column:

<dxg:GridControl.Columns>
    <dxg:GridColumn FieldName="JobTitle" Width="Auto"/>
    <dxg:GridColumn FieldName="FullName"/>
    <dxg:GridColumn FieldName="BirthDate"/>
    <dxg:GridColumn FieldName="Country"/>
    <dxg:GridColumn FieldName="Phone"/>
</dxg:GridControl.Columns>

When you change a column’s width, the GridControl stops recalculating the optimal width for this column. Set the BaseColumn.AllowResizing property to false to prohibit end users from editing the column.

Note

If the TableView.AutoWidth / TreeListView.AutoWidth property value is true, do not set a column’s width to Auto.

Best Fit

The GridControl can automatically calculate and apply the optimal width required for a column to completely display its contents. Refer to the Best Fit topic for more information.

Match the Total Column Width with the Grid Width

The GridControl can change column widths automatically to match the total columns’ width with the grid’s width. Set the TableView.AutoWidth / TreeListView.AutoWidth property to true to enable this behavior. In this case, changing the width of one column automatically changes the widths of other columns. To obtain the actual width of columns, use their BaseColumn.ActualWidth property.

To prevent the width of an individual column from being changed when resizing other columns, set its BaseColumn.FixedWidth property to true.

To specify the column’s minimum and maximum width, use the BaseColumn.MinWidth and BaseColumn.MaxWidth properties respectively.

Note

The TableView.AutoWidth / TreeListView.AutoWidth property works only when the GridControl has a finite width.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Width property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also