Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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

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

#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:

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();
}

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