Version

Locking/Unlocking Component Areas (xamPivotGrid)

Purpose

This topic explains, with code examples, how to lock/unlock component areas of the xamPivotGrid™.

Required Background

The following table lists the materials required as a prerequisite to understanding this topic.

Locking/Unlocking Component Areas – Conceptual Overview

Locking/Unlocking component areas summary

Setting areas as locked or unlocked, is managed by the following AreaFieldSettings class object contains the Boolean properties:

By default, all these areas are unlocked. (The properties are set to true .)

Property settings

The following table maps the tasks related to locking and unlocking components to the property settings that configure them.

In order to: Use this property: And set it to:

Lock rows area

false

Lock columns area

false

Lock filters area

false

Lock measures area

false

Unlock rows area

true

Unlock columns area

true

Unlock filters area

true

Unlock measures area

true

Example

The following settings lock column editing and the ability to drag-drop onto this area. The remaining areas are not locked.

Property Value

AllowRowsEditing

true

AllowColumnsEditing

false

AllowFiltersEditing

true

AllowMeasuresEditing

true

Note
Note:

The default value of each of these properties is true, the setting of the value true isn’t necessary and only shown for demonstration purposes.

Code

The following code implements the settings in the Example.

In C#:

((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowRowsEditing = true;
((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowColumnsEditing = false;
((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowFiltersEditing = true;
((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowMeasuresEditing = true;

In Visual Basic:

DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowRowsEditing = True
DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowColumnsEditing = False
DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowFiltersEditing = True
DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowMeasuresEditing = True

Locking/Unlocking Component Areas – Code Example

Introduction

This code example loads a xamPivotGrid with sample data, and uses check boxes to programmatically enable and disable the locking and unlocking of the rows, columns, filters, and measure areas of the grid and also on the xamPivotDataSelector™.

Preview

The following screenshot is a preview of the final result. Overlaid boxes in red highlight the locked components.

Locking Components 1.png

Prerequisites

To complete the procedure, you need the following:

  • A copy the of the SampleFlatDataSourceForLiveUpdate class in your application.

  • NuGet package references:

    • Infragistics.WPF.PivotGrid

    • Infragistics.WPF.Olap.FlatData

    • Infragistics.WPF.Olap.Xmla

Note
Note:

The data source type of the xamPivotGrid control determines what OLAP NuGet package references are required. Refer to the Deploying Your Application topic for the complete list of required assemblies used by components of the xamPivotGrid control and its data sources.

Overview

This topic takes you step-by-step toward implementing lockable components. The following is a conceptual overview of the process:

  1. Adding the namespace declarations

  2. Referencing the data source

  3. Adding the xamPivotGrid and xamPivotDataSelector controls

  4. Binding the data source

  5. Handling the user action

Steps

The following steps demonstrate how to create row groups.

Add the namespace declarations.

  1. Add the namespace attributes to your XAML source file’s root tag.

    In XAML:

    xmlns:ig="http://schemas.infragistics.com/xaml"
    xmlns:local="clr-namespace:IGPivotGrid.Controls"
  2. Declare namespace references to your code behind.

    In C#:

    using IGPivotGrid.Controls;
    using Infragistics.Olap;
    using Infragistics.Olap.Xmla;

    In Visual Basic:

    Imports IGPivotGrid.Controls
    Imports Infragistics.Olap
    Imports Infragistics.Olap.Xmla
    Note
    Note:

    IGPivotGrid.Controls is the namespace in which the SampleFlatDataSourceForLiveUpdate class is defined. This namespace might vary depending on where you added SampleFlatDataSourceForLiveUpdate class in your project.

  3. Reference the data source.

    Reference the data source in the Page.Resources element.

    In XAML:

    <Page.Resources>
        <ResourceDictionary>
            <local:SampleFlatDataSourceForLiveUpdate x:Key="FlatDataSource" />
        </ResourceDictionary>
    </Page.Resources>
  4. Add the xamPivotGrid and xamPivotDataSelector controls.

    1. Define the column layout for the LayoutRoot grid.

      In XAML:

      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
          <RowDefinition Height="*" />
          <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
    2. Add the xamPivotGrid, option check boxes, and the xamPivotDataSelector.

      The DataSource attribute references the FlatDataSource that was defined in the Page.Resources.

      In XAML:

      <ig:XamPivotGrid
          x:Name="pivotGrid"
          DataSource="{StaticResource FlatDataSource}"
          AllowCompactLayout="True"
          BorderThickness="0">
      </ig:XamPivotGrid>
      <TextBlock Grid.Row="1"
          Text="{Binding Source={StaticResource Strings},
              Path=XPG_EnableDisable_Components}" />
      <StackPanel x:Name="SelectorPanel" Grid.Row="1" Orientation="Horizontal"
                        ScrollViewer.HorizontalScrollBarVisibility="Auto"
                        Margin="5, 15, 5, 5">
          <CheckBox x:Name="RowEditing" IsChecked="True"
              Margin="5" Click="Feature_Click"
              Content="{Binding Source={StaticResource Strings}, Path=XPG_Rows}" />
          <CheckBox x:Name="ColumnsEditing" IsChecked="True"
              Margin="5" Click="Feature_Click"
              Content="{Binding Source={StaticResource Strings}, Path=XPG_Columns}" />
          <CheckBox x:Name="FiltersEditing" IsChecked="True"
              Margin="5" Click="Feature_Click"
              Content="{Binding Source={StaticResource Strings}, Path=XPG_Filters}" />
          <CheckBox x:Name="MeasuresEditing" IsChecked="True"
          Margin="5" Click="Feature_Click"
          Content="{Binding Source={StaticResource Strings}, Path=XPG_Measures}" />
      </StackPanel>
      <ig:Expander Grid.Column="1" Grid.RowSpan="2" IsExpanded="True">
          <ig:XamPivotDataSelector x:Name="dataSelector"
              DataSource="{StaticResource FlatDataSource}" />
      </ig:Expander>
  5. Bind the data source.

    1. In the code behind, add a handler for the Loaded event underneath the called method, InitializeComponent.

      In C#:

      public LockableComponents()
      {
          InitializeComponent();
          this.Loaded += OnSampleLoaded;
      }

      In Visual Basic:

      Public Sub New()
          InitializeComponent()
          Me.Loaded = OnSampleLoaded
      End Sub
    2. Inside the Loaded event handler, reference and load the schema of data source.

      In C#:

      void OnSampleLoaded(object sender, RoutedEventArgs e)
      {
            SampleFlatDataSourceForLiveUpdate dataSource = this.Resources["FlatDataSource"] as SampleFlatDataSourceForLiveUpdate;
            if (dataSource != null)
                  dataSource.LoadSchemaAsync();
      }

      In Visual Basic:

      Private Sub OnSampleLoaded(sender As Object, e As RoutedEventArgs)
            Dim dataSource As SampleFlatDataSourceForLiveUpdate = TryCast(Me.Resources("FlatDataSource"), SampleFlatDataSourceForLiveUpdate)
            If dataSource IsNot Nothing Then
                  dataSource.LoadSchemaAsync()
            End If
      End Sub
  6. Handling the user action.

    In the code behind, add a handler for the Click event of the CheckBox control.

    In C#:

    private void Feature_Click(object sender, RoutedEventArgs e)
    {
        FrameworkElement element = sender as FrameworkElement;
        CheckBox cb = sender as CheckBox;
        if (element == null || cb == null)
            return;
        switch (element.Name)
        {
            case "RowEditing":
                ((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowRowsEditing =
                    (Boolean)cb.IsChecked;
                break;
            case "ColumnsEditing":
                ((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowColumnsEditing =
                    (Boolean)cb.IsChecked;
                break;
            case "FiltersEditing":
                ((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowFiltersEditing =
                    (Boolean)cb.IsChecked;
                break;
            case "MeasuresEditing":
                ((DataSourceBase)pivotGrid.DataSource).AreaFieldSettings.AllowMeasuresEditing =
                    (Boolean)cb.IsChecked;
                break;
          }
    }

    In Visual Basic:

    Private Sub Feature_Click(sender As Object, e As RoutedEventArgs)
        Dim element As FrameworkElement = TryCast(sender, FrameworkElement)
        Dim cb As CheckBox = TryCast(sender, CheckBox)
        If element Is Nothing OrElse cb Is Nothing Then
            Return
        End If
        Select Case element.Name
            Case "RowEditing"
                DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowRowsEditing = DirectCast(cb.IsChecked, [Boolean])
                Exit Select
            Case "ColumnsEditing"
                DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowColumnsEditing = DirectCast(cb.IsChecked, [Boolean])
                Exit Select
            Case "FiltersEditing"
                DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowFiltersEditing = DirectCast(cb.IsChecked, [Boolean])
                Exit Select
            Case "MeasuresEditing"
                DirectCast(pivotGrid.DataSource, DataSourceBase).AreaFieldSettings.AllowMeasuresEditing = DirectCast(cb.IsChecked, [Boolean])
                Exit Select
        End Select
    End Sub

Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic introduces the locking components feature of the xamPivotGrid and the end-user functionality it provides.