[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Collapse]Pivot Grid
   [Expand]Getting Started
   [Expand]Fundamentals
   [Expand]Binding to Data
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Collapse]Layout
     Field Location and Order
     Data Cell Layout
     Field Groups
    [Expand]Customization Form
     Best Fit
     Save and Restore Layout
   [Expand]Focus and Navigation
   [Expand]Printing and Exporting
   [Expand]Appearance
   [Expand]Design-time Features
   [Expand]Miscellaneous
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
   [Expand]Member Tables
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Best Fit

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

Expanded 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.

Note

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

Expanded End-User Capabilities

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

Tip

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

Expanded 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.

Is this topic helpful?​​​​​​​