- 2 minutes to read
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.
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:
Depending on the particular overload, applies the Best Fit:
Resizes the specified column to the minimum width required to completely display its contents.
Resizes the specified row to the minimum height required to completely display its contents.
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.
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.
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).