We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to create a simple pivot grid?

Thread ID:





99714 Jun 7,2011 07:05 AM UTC Jun 14,2011 05:28 AM UTC WinForms 2
Tags: GridControl
Nihar Ranjan Dalai
Asked On June 7, 2011 07:05 AM UTC


I have gone through your Pivot grid sample and it looks good. But, how do I use this control? From what I understand, the user can drag and drop columns onto the pivoting areas to get the grid pivoted. What if I want the pivoting to be done programatically? Can this be achieved? Actually, I have a grid which is bound to an IList data source and I have no knowledge of the columns.

Moreover, if I use this pivot grid in an enterprise application, do you give full support for the component?


Nihar Ranjan Dalai
Replied On June 7, 2011 10:53 AM UTC


To be a bit elaborate, I wish to achieve the following things using your Pivot Grid Control. I am using the Pivot Grid Demo present in your sample browser as a reference implementation.

1) I need to have pivoting based on two columns. In the first snapshot attached, it is done on the columns - State and City. The remaining columns should be visible as data rows, only that their values should contain the sum of the individual cells (for all columns), as is shown in the snapshot.

2) I need to do all pivoting programmatically and not by using drag and drop.

3) I need to be able to select all the rows for the category by clicking on the pivoted cell(or on the row header if available).

4) Drop areas are required to be hidden.

5) On clicking a any data cell, whole row should be selected.

6) Single cell selection should be disabled.

Please find attached a snapshot of the expected pivot grid control.



Jisha Joy [Syncfusion]
Replied On June 14, 2011 05:28 AM UTC

Hi Nihar,

The pivot grid comprises of the following components.

Display Grid - Displays the data extracted from the underlying database.

Pivot Table Field List - Lists the available fields from the database. Provides a way to add/remove the fields to/from the grid.

Drag-Drop Areas - Serves as a view state of the pivot grid, where you can rearrange the fields by doing a drag-and-drop operation between the row and column label areas.

The following code allows us to display the values as desired to be populated in the main grid. Please refer to the following code in the PivotGridControl.cs file.

void gridFields_CheckBoxClick(object sender, GridCellClickEventArgs e)
int rowIndex = e.RowIndex < 2 ? 2 : e.RowIndex;
if (gridFields[rowIndex, 0].Text == "0")
//this.gridRows[this.gridRows.RowCount, 0].Text = gridFields[e.RowIndex, 0].Description;
this.gridRows.Rows.InsertRange(this.gridRows.RowCount, 1);
this.gridRows[this.gridRows.RowCount - 1, 0].Text = gridFields[rowIndex, 0].Description;
PerformLayout(gridRows, null);
int location;
for (int i = 0; i < 4; i++)
GridList grid = FindField(gridFields[rowIndex, 0].Description, out location) as GridList;
if (grid != null && location != -1)
grid.Rows.RemoveRange(location, location);
PerformLayout(grid, null);
You can prevent the cell selection and allow row selection when clicking on the cell by setting the following properties,

gridMainDisplay.ListBoxSelectionMode = SelectionMode.One;
gridMainDisplay.AllowSelection = GridSelectionFlags.None;



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon