GridView.BestFitColumns() Method
Adjusts column widths so that columns fit their content in an optimal way.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Remarks
Call the BestFitColumns
method to resize columns to the minimum width required to accommodate the content of the following elements:
- column header
- footer summary cell
- data cells
- error icons in data cells (based on the GridOptionsView.BestFitUseErrorInfo property value)
Note
Call the GridControl.ForceInitialize method first to invoke the best fit functionality in the form’s Load
event handler.
Specific Notes
If the GridOptionsView.ColumnAutoWidth property is enabled, the
BestFitColumns
method resizes columns to fit their content within the View’s width. Cell content may still be truncated.The
BestFitColumns
method retains a column’s width if the column’s OptionsColumn.FixedWidth option is enabled or the OptionsColumn.AllowSize property is disabled.A
BestFitColumns
method call has no effect if the GridOptionsCustomization.AllowColumnResizing option is disabled.
Example
The following code snippet updates column widths when users change cell values:
private void GridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) {
gridView1.BestFitColumns();
}
Related Settings
API | Description |
---|---|
Gets or sets the number of data rows to process for optimal width calculation. | |
Gets or sets whether cell error icons are taken into account when calculating the “best width” for columns. | |
Gets or sets whether column best-fit resizing operations should prioritize precision or speed. |
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the BestFitColumns() method.
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.