New to Telerik UI for WinForms? Download free 30-day trial

Customizing RadPivotFieldList

RadPivotFieldList can be customized by accessing the elements building its controls or by handling events and define which fields to be extracted and displayed.

Visual Field Manipulation

RadPivotFieldList internally contains a RadTreeView built with nodes coming from the data source object as fields. The tree can be easily accessed and its elements modified.

Before Sorting After Sorting
WinForms RadPivotGrid Before Sorting WinForms RadPivotGrid After Sorting

Sorting the Nodes

this.radPivotFieldList1.FieldsControl.SortOrder = System.Windows.Forms.SortOrder.Ascending;
Before Hiding After Hiding
WinForms RadPivotGrid Before Hiding WinForms RadPivotGrid After Hiding

Hiding Nodes

The nodes in the pivot field list are built dynamically so in order to hide a particular node and persist the changes we would need to handle the UpdateCompleted event.

this.radPivotGrid1.UpdateCompleted += radPivotGrid1_UpdateCompleted;
private void radPivotGrid1_UpdateCompleted(object sender, EventArgs e)
{
    RadTreeNode promotionField = this.radPivotFieldList1.FieldsControl.Nodes.Where(n => n.Text == "Promotion").FirstOrDefault();
    if (promotionField != null)
    {
        promotionField.Visible = false;
    }
}

Remove Fields Logically

In the case of a LocalSourceDataProvider object used to populate the items in RadPivotGrid, the nodes can be manipulated by handling the AddingContainerNode and GetDescriptionsDataAsyncCompleted events.

Setup the Providers

this.provider = new LocalDataSourceProvider() { ItemsSource = this.orders };
LocalDataSourceFieldDescriptionsProvider descriptionProvider = new LocalDataSourceFieldDescriptionsProvider();
descriptionProvider.AddingContainerNode += descriptionProvider_AddingContainerNode;
descriptionProvider.GetDescriptionsDataAsyncCompleted += descriptionProvider_GetDescriptionsDataAsyncCompleted;
this.provider.FieldDescriptionsProvider = descriptionProvider;
Before Canceling After Canceling
WinForms RadPivotGrid Before Canceling WinForms RadPivotGrid After Canceling

Cancel Adding a Particular Node

private void descriptionProvider_AddingContainerNode(object sender, ContainerNodeEventArgs e)
{
    if (e.ContainerNode.Name == "Promotion")
    {
        e.Cancel = true;
    }
}
Before Removing After Removing
WinForms RadPivotGrid Before Removing WinForms RadPivotGrid After Removing

Remove a Child Date Node

private void descriptionProvider_GetDescriptionsDataAsyncCompleted(object sender, GetDescriptionsDataCompletedEventArgs e)
{
    ContainerNode dateNode = e.DescriptionsData.RootFieldInfo.Children.Where(n => n.Name == "Date").FirstOrDefault();
    if (dateNode != null)
    {
        FieldInfoNode yearNode = dateNode.Children.Where(n => n.Name == "Date.Year").FirstOrDefault() as FieldInfoNode;
        if (yearNode != null)
        {
            dateNode.Children.Remove(yearNode);
        }
    }
}

Formatting Nodes

The nodes within the RadPivotFieldList can be formatted. You can easily format node elements by handling the NodeFormatting event as follows:

this.radPivotFieldList1.FieldsControl.NodeFormatting += this.FieldsControl_NodeFormatting;

Then, introduce the desired customizations to NodeElements:

private void FieldsControl_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
    if (e.Node.Text == "Product")
    {
        e.NodeElement.ContentElement.Text = "Custom Product";
    }
    if (e.Node.CheckState == Telerik.WinControls.Enumerations.ToggleState.On)
    {
        e.NodeElement.ContentElement.ForeColor = Color.Red;
        e.Node.BackColor = Color.LightGray;
        e.Node.GradientStyle = GradientStyles.Solid;
    }
    else
    {
        e.NodeElement.ContentElement.ResetValue(LightVisualElement.ForeColorProperty, ValueResetFlags.Local);
        e.NodeElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.NodeElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
    }
}

|WinForms RadPivotGrid Formatting Nodes

Please note that you should always provide an 'else' clause in the NodeFormatting event where you should reset all of the introduced customizations. More information is available here.