Back to Devexpress

GridOptionsView.ColumnAutoWidth Property

windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridoptionsview-3384ca50.md

latest5.4 KB
Original Source

GridOptionsView.ColumnAutoWidth Property

Gets or sets a value that specifies columns automatically adjust their width to fit the grid’s width.

Namespace : DevExpress.XtraGrid.Views.Grid

Assembly : DevExpress.XtraGrid.v25.2.dll

NuGet Packages : DevExpress.Win.Grid, DevExpress.Win.Navigation

Declaration

csharp
[DefaultValue(true)]
[XtraSerializableProperty]
public virtual bool ColumnAutoWidth { get; set; }
vb
<DefaultValue(True)>
<XtraSerializableProperty>
Public Overridable Property ColumnAutoWidth As Boolean

Property Value

TypeDefaultDescription
Booleantrue

true to enable the column auto-width feature; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to ColumnAutoWidth
GridView

.OptionsView .ColumnAutoWidth

|

Remarks

The following example handles the check edit’s CheckedChanged event to enable/disable automatic column width calculation:

csharp
void checkEdit1_CheckedChanged(object sender, EventArgs e) {
    gridView1.OptionsView.ColumnAutoWidth = checkEdit1.Checked;
    if (!checkEdit1.Checked)
        gridView1.BestFitColumns();
}
vb
Private Sub checkEdit1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    gridView1.OptionsView.ColumnAutoWidth = checkEdit1.Checked
    If Not checkEdit1.Checked Then
        gridView1.BestFitColumns()
    End If
End Sub

The following animation shows the result:

Note

If the column’s OptionsColumn.FixedWidth option is enabled, the column’s width is not changed when applying the auto width feature.

Read the following topic for additional information about grid columns: Data Grid Columns.

The following code snippets (auto-collected from DevExpress Examples) contain references to the ColumnAutoWidth 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.

winforms-grid-move-cell-using-drag-drop/CS/Form1.cs#L16

csharp
InitializeComponent();
gridView1.OptionsView.ColumnAutoWidth = false;
WindowState = FormWindowState.Maximized;

winforms-grid-copy-cell-value-to-other-cells-by-dragging-its-right-bottom-edge/CS/Form1.cs#L19

csharp
WindowState = FormWindowState.Maximized;
gridView1.OptionsView.ColumnAutoWidth = false;
gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDownFocused;

winforms-grid-move-cell-using-drag-drop/VB/Form1.vb#L15

vb
InitializeComponent()
gridView1.OptionsView.ColumnAutoWidth = False
WindowState = FormWindowState.Maximized

winforms-grid-copy-cell-value-to-other-cells-by-dragging-its-right-bottom-edge/VB/Form1.vb#L19

vb
WindowState = FormWindowState.Maximized
gridView1.OptionsView.ColumnAutoWidth = False
gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDownFocused

See Also

FixedWidth

BestFitColumns()

Grid Columns

GridOptionsView Class

GridOptionsView Members

DevExpress.XtraGrid.Views.Grid Namespace