Edit this page


As of R3 2016 RadPivotGrid provides the option to select multiple or individual cells, rows and columns using the mouse.

In this topic we will go through the following sections:

Enabling Selection

By default the selection functionality is disabled and to turn it on you have to set AllowSelection property of the PivotGrid to true as in Example 1.

[XAML] Example 1: Enabling selection

<pivot:RadPivotGrid Name="radPivotGrid1" DataProvider="{StaticResource LocalDataProvider}" AllowSelection="True">

Figure 1: RadPivotGrid with enabled cell selection

Additionally, you will be able to select separate blocks of cells by pressing Ctrl key or extend the current selection by pressing Shift key.

Figure 2: RadPivotGrid with separate blocks of cells selected

Clicking on any of the headers will select the corresponding row/column as shown in the next figures.

Figure 3: RadPivotGrid with selected row by clicking on the header

Figure 4: RadPivotGrid with a few rows selected by clicking on the headers and pressing Ctrl key

Selection Commands

RadPivotGrid provides the following commands through its PivotGridCommands static class for handling the cells selection:

  • CopySelection – used to copy the selected cells data into the clipboard.
  • ClearSelection – clears the current selection.

Example 2 demonstrates how you could use CopySelection and ClearSelection commands together with a button.

[XAML] Example 2: Using PivotGrid Commands

<Button Content="Copy Selected Cells" 
    Command="{x:Static pivot:PivotGridCommands.CopySelection}" 
    CommandTarget="{Binding ElementName=radPivotGrid1}" />
<Button Content="Clear Selected Cells" 
    Command="{x:Static pivot:PivotGridCommands.ClearSelection}" 
    CommandTarget="{Binding ElementName=radPivotGrid1}" />

After copying the selected cells, you could easily get that data from the clipboard with code as shown in Example 3.

[XAML] Example 3: Getting selected cells from the clipboard

var result = Clipboard.GetText(TextDataFormat.Text);

Figure 5 shows the result after copying certain cells selection.

Figure 5: Getting the selected cells from the clipboard

You could also directly paste the clipboard data into Excel, for example, as illustrated in Figure 6.

Figure 6: Pasting the selected cells data into Excel

Selection Events

  • SelectionChanged - this event occurs when the current selection of RadPivotGrid has changed. The passed event argument is of type System.EventArgs.

Styling Selection Overlay

Any changes in the appearance of the selection overlay should be made inside the SelectionOverlayStyle. Example 4 shows the SelectionOverlayStyle with the provided properties.

[XAML] Example 4: SelectionOverlayStyle

<Style x:Key="SelectionOverlayStyle" TargetType="pivot:SelectionOverlay">
    <Setter Property="SelectionFill" Value="{StaticResource SelectionFill}"/>
    <Setter Property="SelectionStroke" Value="{StaticResource SelectionStroke}"/>
    <Setter Property="SelectionStrokeThickness" Value="1"/>
    <Setter Property="SelectionPadding" Value="0"/>
    <Setter Property="SelectionCellFill" Value="{StaticResource SelectionCellFill}"/>
    <Setter Property="SelectionCellStroke" Value="{StaticResource SelectionCellStroke}"/>
    <Setter Property="SelectionCellPadding" Value="0"/>
    <Setter Property="SelectionCellStrokeThickness" Value="1"/>
    <Setter Property="DrawSelectionCell" Value="True"/>

SelectionFill/SelectionStroke/SelectionStrokeThickness and SelectionPadding properties refer to the whole selection blocks, while the SelectionCell properties refer to the current selection cell.

You could easily disable marking the current selection cell by setting DrawSelectionCell to False as in Example 5.

[XAML] Example 5: Disable marking the current selection cell

<Style x:Key="SelectionOverlayStyle1" TargetType="pivot:SelectionOverlay">           
    <Setter Property="DrawSelectionCell" Value="False"/>
<Style TargetType="pivot:SelectionOverlay" BasedOn="{StaticResource SelectionOverlayStyle1}"/>

Figure 7 shows how the selection looks before and after applying the Style from Example 5.

Figure 7: Selection with DrawSelectionCell set to both true and false