Skip to main content Skip to footer

How to Add a WinForms Pivot Table to a .NET Application

Quick Start Guide
Tutorial Concept

This tutorial shows developers how to add a Pivot Table to a .NET WinForms spreadsheet application. Learn how to show familiar Pivot Table dialogs and apply styling to fit your applications needs.

What You Will Need
Controls Referenced

Spread.NET WinForms Component | C# .NET Spreadsheet

Download Trial | Demos | Documentation

Applications often need tools that help users quickly analyze large datasets. However, reviewing rows of raw data isn’t always the most effective way to uncover insights. Pivot Tables make this easier by allowing users to summarize, group, and reorganize data to quickly identify trends and patterns.

In this tutorial, we’ll demonstrate how to build a Pivot Table using the WinForms spreadsheet component, Spread.NET, enabling users to explore and analyze data directly within a Windows desktop spreadsheet application.

Download a Trial of this WinForms Spreadsheet Component with Pivot Table Capabilities Today!

How to Create a WinForms Pivot Table App

Download a finished sample application here.


Create a .NET WinForms App (C#)

In Visual Studio, create a new Windows Forms App (C#) project.

Create a C# WinForms Pivot Table App

Name the project and select .NET 8.

Create a .NET 8 WinForms Pivot Table App


Install the .NET Spreadsheet Component

Next, download the latest Spread.NET release and install it on your machine. See our Quick Start documentation for more information on getting up and running.

Download a Trial of this WinForms Spreadsheet Component with Pivot Table Capabilities Today!

Alternatively, Spread.NET is accessible via NuGet by searching for “MESCIUS Spread WinForms”, and selecting GrapeCity.Spread.WinForms.

Install WinForms Spreadsheet Component from NuGet | Spread.NET


Add a .NET Spreadsheet Component on the Form

Drag and drop the .NET spreadsheet component onto the WinForms form designer.

Adding a .NET Spreadsheet Component to a WinForms App

Right click on the spreadsheet, and select “View Code”. This will take us to the associated form’s CS file. Here we will add some sample data to the worksheet:

// Access the workbook and worksheet
IWorkbook workbook = fpSpread1.AsWorkbook();
IWorksheet sheet1 = workbook.ActiveSheet;
// Add some dummy data
sheet1.SetValue(0, 0, new object[,]
{
  { "OrderDate", "Region", "City", "Category", "Product", "Quantity" },
  { "2025-07-01", "East", "Jersey", "Breads", "Bakery", 1120 },
  { "2025-07-01", "East", "Jersey", "Breads", "Cookie", 563 },
  { "2025-07-02", "East", "Washington, DC", "Breads", "Bakery", 1281 },
  { "2025-07-02", "East", "Washington, DC", "Breads", "Cookie", 546 },
  { "2025-07-01", "East", "Jersey", "Beverages", "Coffee", 326 },
  { "2025-07-02", "East", "Washington, DC", "Beverages", "Coffee", 205 },
  { "2025-07-02", "East", "Washington, DC", "Beverages", "Juice", 186 },
  { "2025-07-01", "West", "San Francisco", "Breads", "Bakery", 1262 },
  { "2025-07-01", "West", "San Francisco", "Breads", "Cookie", 349 },
  { "2025-07-01", "West", "Seattle", "Breads", "Bakery", 524 },
  { "2025-07-01", "West", "Seattle", "Breads", "Cookie", 196 },
  { "2025-07-01", "West", "San Francisco", "Beverages", "Coffee", 363 },
  { "2025-07-01", "West", "Seattle", "Beverages", "Coffee", 100 },
  { "2025-07-02", "East", "Jersey", "Beverages", "Juice",  120 },
  { "2025-07-02", "West", "San Francisco", "Breads", "Bakery", 350 },
  { "2025-07-02", "West", "Seattle", "Beverages", "Tea", 180 },
  { "2025-07-02", "East", "Jersey", "Breads", "Cookie", 75 },
  { "2025-07-03", "West", "San Francisco", "Beverages", "Juice", 210 },
  { "2025-07-03", "East", "Boston", "Breads", "Bakery", 420 },
});

Next, we will add a simple table to the spreadsheet to house the sample data.

// Create a table
ITable table = sheet1.Tables.Add(0, 0, 19, 5);

Run the application, notice the .NET WinForms workbook now shows the sample data within a table.

Adding .NET WinForms Pivot Table Sample Data


Create a WinForms Pivot Table

Now that the sample dataset has been added to a table, we can create a Pivot Table to summarize and analyze the data.

Spread for WinForms allows Pivot Tables to be created from either a cell range or a structured table. In this example, we will use the table we previously created as the Pivot Table data source. The Pivot Table will summarize Quantity values while organizing the data by region, city, product category, and order date.

Step 1: Create a PivotCache

A PivotCache stores a snapshot of the source data and acts as the data source for the Pivot Table.

// Step 1: Create a PivotCache based on the table.
IPivotCache pvCache = fpSpread1.AsWorkbook().PivotCaches.Create(table);

Step 2: Create the Pivot Table

Next, create the Pivot Table using the PivotCache’s CreatePivotTable method and place it in the worksheet starting at cell I1.

// Step 2: Create a PivotTable and place it at cell I1.
IPivotTable pvTable = pvCache.CreatePivotTable(sheet1.Cells["I1"]);

Step 3: Access the PivotFields Collection

The PivotFields collection provides access to all fields from the source table so they can be assigned to rows, columns, values, or filters.

// Step 3: Get pivot fields from the PivotTable.
IPivotFields pvFields = pvTable.PivotFields;

Step 4: Add the Values Field

Using the AddDataField method, add the Quantity column as a data field and summarize it using the Sum aggregation function.

// Step 4: Add "Quantity" as a data (Values) field, summarized by Sum.
pvTable.AddDataField(pvFields["Quantity"], "Sum of quantity", ConsolidationFunction.Sum);

 Step 5: Configure the Row Fields

Set Region and City as row fields so the Pivot Table groups results geographically.

// Step 5: Set "Region" and "City" as row fields.
pvFields["Region"].Orientation = PivotFieldOrientation.Row;
pvFields["City"].Orientation = PivotFieldOrientation.Row;


Step 6:  Configure the Column Fields

Add Category and Product as column fields to further break down the summarized data.

// Step 6: Set "Category" and "Product" as column fields.
pvFields["Category"].Orientation = PivotFieldOrientation.Column;
pvFields["Product"].Orientation = PivotFieldOrientation.Column;

Step 7: Add a Filter Field

Finally, add OrderDate as a page field so users can filter the Pivot Table by specific dates. To learn more, see the Filtering Pivot Table Fields documentation.

// Step 7: Set "OrderDate" as the page (Filter) field.
pvFields["OrderDate"].Orientation = PivotFieldOrientation.Page;

Once these fields are configured, the WinForms Pivot Table automatically generates a summarized view of the dataset directly within the WinForms spreadsheet.

Allow .NET Users to Work with Pivot Tables in WinForms Apps


Add a Pivot Table Field's Panel

The Spread.NET WinForm’s spreadsheet support several built-in dialogs that allow users to manage and configure Pivot Tables during run-time using a familiar UI. One common Pivot Table feature is the Field Panel.This dialog displays the field list, enabling users to drag and drop fields to define the rows, columns, values, and filters for the WinForms Pivot Table.

Developers can easily display this panel programmatically using the BuiltInDialogs.PivotTableFields method.

BuiltInDialogs.PivotTableFields(fpSpread1, pvTable).ShowDialog();

When the application runs, the PivotTable Fields panel appears along with the spreadsheet, allowing users to dynamically adjust the Pivot Table layout without changing the application code.

WinForms Pivot Table Fields Side Bar


Set Pivot Table Styles

After creating the Pivot Table, users can change its appearance by applying a built-in Pivot Table style. Spread for WinForms includes several predefined styles that can be assigned using the TableStyle property of the IPivotTable interface

Custom Pivot Table styles are also supported if you need more control over formatting. For this example, use one of the built-in styles from the workbook’s TableStyles collection and assign it to the Pivot Table.

ITableStyle style = fpSpread1.AsWorkbook().TableStyles[BuiltInPivotStyles.PivotStyleDark10];
pvTable.TableStyle = style;

Run the application and notice the Pivot Table has been updated with the selected style.

Change the Style of the WinForms Pivot Table

See the Setting Pivot Table Styles documentation to learn more.


Learn More About this .NET WinForms Spreadsheet Component

This article only scratches the surface of the full capabilities of Spread.NET, the .NET spreadsheet component. Review the documentation to see some of the many available features, and download our demo explorer to see the features in action and interact with the sample code. 

Integrating a spreadsheet component into your applications allows you to customize your users' experience and provide them with familiar spreadsheet functionality without referring them to an external program. 

To learn more about Spread.NET and the new features added in the latest release, check out our release pages.

Tags:

comments powered by Disqus