Skip to main content
A newer version of this page is available. .

Best Fit

  • 2 minutes to read

The PivotGridControl control provides the ability to calculate and apply the optimal width required for a column to display its entire content.

Best Fit Overview

The Best Fit feature can be applied to an individual column, as well as to all columns displayed within 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 for which 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 columns that correspond to the current field to the minimum width required to completely display the column’s contents.
PivotGridControl.BestFitColumnArea Resizes columns in the Data Area to the minimum width required to completely display their contents.
PivotGridControl.BestFitRowArea Resizes columns that display row field values to the minimum width required to completely display their contents.

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

Note

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 (if allowed) by double-clicking the right border of the column.

EndUserCapabilities_ResizingColumns

Best Fit Options

You can specify which visual elements are taken into account when calculating the optimal width for columns. To do this, use the PivotGridOptionsBehaviorBase.BestFitMode property. By default, the column width is calculated based on the content of data cells, field values and field headers.

To allow automatic Best Fit for all fields that have been dragged and dropped to another location, use the PivotGridOptionsBehavior.ApplyBestFitOnFieldDragging property.

Use the PivotGridOptionsBehavior.BestFitConsiderCustomAppearance property to specify whether appearance settings made while handling the PivotGridControl.CustomAppearance event should be taken into account when calculating minimum column width for Best Fit. Note that Best Fit performs slower if the PivotGridOptionsBehavior.BestFitConsiderCustomAppearance property is set to true.