GridColumn.Width Property

Gets or sets the column width.

Namespace: DevExpress.XtraGrid.Columns

Assembly: DevExpress.XtraGrid.v20.1.dll

Declaration

[DXCategory("Appearance")]
[DefaultValue(75)]
[XtraSerializableProperty(XtraSerializationFlags.AutoScaleX)]
[XtraSerializablePropertyId(3)]
public virtual int Width { get; set; }
<DXCategory("Appearance")>
<DefaultValue(75)>
<XtraSerializableProperty(XtraSerializationFlags.AutoScaleX)>
<XtraSerializablePropertyId(3)>
Public Overridable Property Width As Integer

Property Value

Type Default Description
Int32

75

The column's width.

Remarks

Use the Width property to set the column width to a custom value. The GridColumn.MinWidth property defines the minimum possible width for the column. If the Width property value is less, it is automatically changed to GridColumn.MinWidth.

You can obtain the actual column width from the GridColumn.VisibleWidth property. This property can be useful in column auto-width mode (GridOptionsView.ColumnAutoWidth), in which column visible widths are automatically calculated to fit the View's width.

Column Auto-Width Mode

In code, to initialize multiple column widths in column auto-width mode (GridOptionsView.ColumnAutoWidth), set the GridColumn.Width settings and wrap these customizations with the BaseView.BeginUpdate and BaseView.EndUpdate method pair. A single column's GridColumn.Width setting needs to be set to a value that is proportional to other column widths, as they will adjust themselves to the grid's width.

In column auto-width mode, the GridColumn.Width and GridColumn.VisibleWidth settings are not synced in the following cases:

However, when you resize any column in auto-width mode, the GridColumn.Width and GridColumn.VisibleWidth settings of all columns are immediately synced. If you then resize the View horizontally, the GridColumn.Width and GridColumn.VisibleWidth settings will be out of sync again.

When you switch the GridOptionsView.ColumnAutoWidth option from true to false, column visible widths are set to the GridColumn.Width settings.

The code sample below illustrates how to set fixed width to the Product Status grid column and variable widths to other columns.


gridView1.Columns["productStatus"].Width = 50;
gridView1.Columns["productStatus"].OptionsColumn.FixedWidth = true;
gridView1.OptionsView.ColumnAutoWidth = true;
See Also