windowsforms-devexpress-dot-xtragrid-dot-views-dot-grid-dot-gridoptionsview-3384ca50.md
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
[DefaultValue(true)]
[XtraSerializableProperty]
public virtual bool ColumnAutoWidth { get; set; }
<DefaultValue(True)>
<XtraSerializableProperty>
Public Overridable Property ColumnAutoWidth As Boolean
| Type | Default | Description |
|---|---|---|
| Boolean | true |
true to enable the column auto-width feature; otherwise, false.
|
You can access this nested property as listed below:
| Object Type | Path to ColumnAutoWidth |
|---|---|
| GridView |
.OptionsView .ColumnAutoWidth
|
The following example handles the check edit’s CheckedChanged event to enable/disable automatic column width calculation:
void checkEdit1_CheckedChanged(object sender, EventArgs e) {
gridView1.OptionsView.ColumnAutoWidth = checkEdit1.Checked;
if (!checkEdit1.Checked)
gridView1.BestFitColumns();
}
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
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
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
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
WindowState = FormWindowState.Maximized
gridView1.OptionsView.ColumnAutoWidth = False
gridView1.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDownFocused
See Also