[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Collapse]Pivot Grid
   [Expand]Getting Started
   [Expand]Fundamentals
   [Expand]Binding to Data
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Collapse]Layout
     Field Groups
     Data Cell Layout
     Field Location and Order
    [Expand]Customization Form
     Best Fit
     Standalone Field Header Areas
     Group Value
     Save and Restore Layout
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Appearance
   [Expand]MVVM Enhancements
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[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 Pivot Grid control provides the capability to automatically calculate and apply the optimal width/height required for a column/row to completely display its contents.

Expanded Best Fit Overview

The Best Fit feature can be applied to an individual column or row, as well as to all columns and rows displayed within the PivotGridControl.

Use the PivotGridControl.BestFit method without parameters to apply Best Fit to all columns/rows. To specify the field whose columns/rows should be automatically adjusted to the optimal width/height, use the PivotGridControl.BestFit method with a PivotGridField parameter.

Use the PivotGridControl.BestFitArea (PivotGridField.BestFitArea) property to specify interface elements (field headers, field values or cells), which should be taken into account when adjusting column widths and row heights.

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

Method

Description

PivotGridControl.BestFit

Depending on the particular overload, applies the Best Fit:

  • to all columns and rows
  • to the columns/rows which correspond to the fields contained within the specified area
  • to the columns/rows which correspond to the specified field

PivotGridControl.BestFitColumn

Resizes the specified column to the minimum width required to completely display its contents.

PivotGridControl.BestFitRow

Resizes the specified row to the minimum height required to completely display its contents.

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

Note

The Best Fit feature cannot be applied to the pivot grid if the PivotGridControl.AllowResizing property is set to false.

The Best Fit is available only after the Pivot Grid Control has been loaded in the visual tree.

Expanded End-User Capabilities

End-users can resize columns to their optimal width (if allowed) by double clicking their right border. Rows are resized by double clicking their bottom border.

Expanded 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 PivotGridControl.BestFitMode (PivotGridField.BestFitMode) property. By default, the column's width (row's height) is calculated based on the text of all cells within this column/row.

To increase the application's performance, the number of cells taken into account when calculating the optimal width/height can be limited by setting the PivotGridControl.BestFitMaxRowCount (PivotGridField.BestFitMaxRowCount) property. By default, this property is set to -1, to indicate that all cells are processed. If the PivotGridControl.BestFitMaxRowCount property is set to a positive value, the PivotGridControl processes the specified number of cells starting from the first visible cell (top visible for columns, and leftmost visible, for rows).

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