Skip to main content

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

public virtual void BestFitColumns()

Remarks

Call the BestFitColumns method to resize columns to the minimum width required to accommodate the content of the following elements:

DevExpress WinForms Data Grid BestFitColumns method

Note

Call the GridControl.ForceInitialize method first to invoke the best fit functionality in the form’s Load event handler.

Specific Notes

Example

The following code snippet updates column widths when users change cell values:

private void GridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) {
  gridView1.BestFitColumns();
}

DevExpress WinForms Data Grid apply BestFit on value change

API

Description

GridOptionsView.BestFitMaxRowCount

Gets or sets the number of data rows to process for optimal width calculation.

GridOptionsView.BestFitUseErrorInfo

Gets or sets whether cell error icons are taken into account when calculating the “best width” for columns.

GridOptionsView.BestFitMode

Gets or sets whether column best-fit resizing operations should prioritize precision or speed.

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.

See Also