Best Fit

  • 2 minutes to read

The PivotGridControl control can use the Best Fit feature to calculate and apply the optimal column width to fit its content.

Best Fit Overview

The Best Fit feature can be applied to an individual column and all columns in the PivotGridControl

Use the PivotGridControl.BestFit method without parameters to apply the Best Fit feature to all columns.

Use the PivotGridControl.BestFit method with a PivotGridField parameter (or the PivotGridField.BestFit method) to specify the field whose columns should be automatically adjusted.

The following table lists the methods used to apply the Best Fit feature:

Method Description
PivotGridControl.BestFit Depending on the specific overload, applies the Best Fit feature to all columns or to the columns that correspond to the specified field.
PivotGridField.BestFit Resizes the field's column(s) to fit the longest text currently displayed in the column.
PivotGridControl.BestFitColumnArea Resizes columns in the Data Area to the minimum width required to display their contents.
PivotGridControl.BestFitRowArea Resizes columns that display row field values to the minimum width required to display their contents.
PivotGridControl.BestFitDataHeaders Resizes the Data Header Area to the minimum width required to display data field headers.

To disable the Best Fit feature, set the PivotGridOptionsBehaviorBase.BestFitMode property to PivotGridBestFitMode.None.


The Best Fit feature cannot be applied within the PivotGridControl.BeginUpdate and PivotGridControl.EndUpdate method calls.

End-User Capabilities

End-users can resize columns to the optimal width by double-clicking the column's right border.



If you do not want the end-users to resize columns, set the PivotGridOptionsCustomizationEx.AllowResizing property to false.

Best Fit Options

You can use the PivotGridOptionsBehaviorBase.BestFitMode property to specify which visual elements are considered when calculating the optimal column width. The column width is calculated based on the content of data cells, field values and field headers.

To calculate column width using the Best Fit algorithm for dragged and dropped fields, use the PivotGridOptionsBehavior.ApplyBestFitOnFieldDragging property.

If you handle the PivotGridControl.CustomAppearance event, set the PivotGridOptionsBehavior.BestFitConsiderCustomAppearance property to true to consider new appearance settings specified in the event handler. Note that Best Fit performs slower if the PivotGridOptionsBehavior.BestFitConsiderCustomAppearance property is set to true.