GridView.BestFitColumns(Boolean) Method
Adjusts column widths so that columns fit their content in an optimal way. The method’s parameter allows you to forcibly adjust column widths regardless of whether column resizing is prohibited.
Namespace: DevExpress.XtraGrid.Views.Grid
Assembly: DevExpress.XtraGrid.v24.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
forceResize | Boolean |
|
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)
Set the forceResize
parameter to true
to forcibly adjust column widths regardless of GridOptionsCustomization.AllowColumnResizing and OptionsColumn.AllowSize property values.
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.
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 snippet (auto-collected from DevExpress Examples) contains a reference to the BestFitColumns(Boolean) 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.