Back to Devexpress

PivotGridControl.BestFit() Method

windowsforms-devexpress-dot-xtrapivotgrid-dot-pivotgridcontrol-0d4f6600.md

latest7.2 KB
Original Source

PivotGridControl.BestFit() Method

Resizes all columns to fit their contents.

Namespace : DevExpress.XtraPivotGrid

Assembly : DevExpress.XtraPivotGrid.v25.2.dll

NuGet Package : DevExpress.Win.PivotGrid

Declaration

csharp
public void BestFit()
vb
Public Sub BestFit

Remarks

The BestFit method resizes all columns to display the entire contents. Call the method after the Pivot Grid loads the data and calculates its layout.

Important

Do not call the BestFit method enclosed in an PivotGridControl.BeginUpdate - PivotGridControl.EndUpdate pair. An exception occurs: “This operation cannot be executed when pivot grid updates are blocked. The control’s visual presentation is created after the EndUpdate method is called, so that you cannot perform actions that affect it within the BeginUpdate and EndUpdate method calls.”

The method applies to the following fields:

Tip

Use the PivotGridControl.BestFitColumnArea and PivotGridControl.BestFitRowArea methods to resize columns that correspond only to column and row fields respectively.

The following code snippets (auto-collected from DevExpress Examples) contain references to the BestFit() method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-pivot-grid-hide-empty-columns-and-rows/CS/Form1.cs#L16

csharp
pivotGridControl1.DataSource = PivotHelper.GetDataTable();
    pivotGridControl1.BestFit();
}

winforms-dashboard-window-calculation-example/CS/WindowCalculationExample/Form1.cs#L73

csharp
if (e.PivotGridControl != null)
        e.PivotGridControl.BestFit();
}

winforms-highlight-pivot-cells-that-correspond-to-a-series-point-on-hover/CS/WindowsApplication53/Form1.cs#L15

csharp
pivotGridControl1.RefreshData();
    pivotGridControl1.BestFit();
}

winforms-pivot-grid-use-a-hidden-field-to-sort-visible-field-values/CS/CustomSortingExample/Form1.cs#L15

csharp
excelDataSource1.Fill();
pivotGridControl1.BestFit();

winforms-pivot-grid-connect-to-an-olap-datasource/CS/WinOlapRetrieveFieldsExample/Form1.cs#L42

csharp
// Resize columns automatically.
pivotGridControl1.BestFit();

winforms-pivot-grid-hide-specific-columns-and-rows/VB/Form1.vb#L17

vb
pivotGridControl1.DataSource = PivotHelper.GetDataTable()
    pivotGridControl1.BestFit()
End Sub

winforms-pivot-grid-hide-empty-columns-and-rows/VB/Form1.vb#L19

vb
pivotGridControl1.DataSource = GetDataTable()
    pivotGridControl1.BestFit()
End Sub

winforms-dashboard-window-calculation-example/VB/WindowCalculationExample/Form1.vb#L59

vb
Private Sub DashboardViewer1_DashboardItemControlUpdated(ByVal sender As Object, ByVal e As DashboardItemControlEventArgs)
    If e.PivotGridControl IsNot Nothing Then e.PivotGridControl.BestFit()
End Sub

winforms-highlight-pivot-cells-that-correspond-to-a-series-point-on-hover/VB/WindowsApplication53/Form1.vb#L19

vb
pivotGridControl1.RefreshData()
    pivotGridControl1.BestFit()
End Sub

winforms-pivot-grid-use-a-hidden-field-to-sort-visible-field-values/VB/CustomSortingExample/Form1.vb#L18

vb
excelDataSource1.Fill()
pivotGridControl1.BestFit()
' Create a hidden field to apply custom sorting

See Also

BestFit()

ApplyBestFitOnFieldDragging

BestFitColumnArea()

BestFitRowArea()

BestFitDataHeaders(Boolean)

PivotGridControl Class

PivotGridControl Members

DevExpress.XtraPivotGrid Namespace