Skip to main content

How to: Display Top N Values

This example demonstrates how to avoid browsing an entire report, but only show the best or worst results. For this purpose, the PivotGridControl provides the Top N Values feature, which can be used to limit the number of displayed field values to the specified number of topmost values according to the sort order.

To enable this feature, the PivotGridField.TopValueCount property must be used. This property allows you to restrict the number of field values that are displayed along the column or row axis.

<Window x:Class="HowToBindToMDB.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        Title="MainWindow" Height="350" Width="525"  Loaded="Window_Loaded">
    <Grid Margin="7">
        <dxpg:PivotGridControl HorizontalAlignment="Left" Name="pivotGridControl1"
                               VerticalAlignment="Top">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField x:Name="fieldCountry" FieldName="Country" Area="RowArea"/>
                <dxpg:PivotGridField x:Name="fieldCustomer" FieldName="Sales Person" Area="RowArea"
                                     SortByField="{Binding ElementName=fieldExtendedPrice}"
                                     Caption="Customer" TopValueCount="3"
                                     TopValueShowOthers="True"
                                     SortOrder="Descending"/>
                <dxpg:PivotGridField x:Name="fieldExtendedPrice" FieldName="Extended Price"
                                     Area="DataArea" CellFormat="c0" />
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>