How to: Localize a Pivot Grid with the Localizer

  • 3 minutes to read

The following example shows how to localize a PivotGridControl via the PivotGridLocalizer class.

In this example, grand total headers ('Grand Total' by default) are replaced with 'Aggregate Total', automatic total header patterns ('{0} Total' by default) are replaced with 'Total for {0}', and the text displayed within the Filter Header Area ('Drop Filter Fields Here' by default) is replaced with 'Filter Header Area is currently empty'. To do this, a PivotGridLocalizer class descendant (CustomDXPivotGridLocalizer) has been created, and its GetLocalizedString method is overridden to replace the default strings.

For other localization approaches, refer to Localization.

View Example

Imports Microsoft.VisualBasic
Imports System.Windows
Imports System.Windows.Data
Imports DevExpress.XtraPivotGrid.Localization
Imports DXPivotGrid_Localization.DataSet1TableAdapters

Namespace DXPivotGrid_Localization
    Partial Public Class MainWindow
        Inherits Window
        Private salesPersonDataTable As New DataSet1.SalesPersonDataTable()
        Private salesPersonDataAdapter As New SalesPersonTableAdapter()
        Public Sub New()
            PivotGridLocalizer.Active = New CustomDXPivotGridLocalizer()
            pivotGridControl1.DataSource = salesPersonDataTable
        End Sub
        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            Dim nwindDataSet As DataSet1 = (CType(Me.FindResource("nwindDataSet"), DataSet1))
            Dim nwindDataSetCategoryProductsTableAdapter As New CategoryProductsTableAdapter()
            Dim categoryProductsViewSource As CollectionViewSource = _
                (CType(Me.FindResource("categoryProductsViewSource"), CollectionViewSource))
        End Sub
    End Class
    Public Class CustomDXPivotGridLocalizer
        Inherits PivotGridLocalizer
        Public Overrides Function GetLocalizedString(ByVal id As PivotGridStringId) As String
            Select Case id
                Case PivotGridStringId.GrandTotal
                    Return "Aggregate Total"
                Case PivotGridStringId.TotalFormat
                    Return "Total for {0}"
                Case PivotGridStringId.FilterHeadersCustomization
                    Return "Filter Header Area is currently empty"
                Case Else
                    Return MyBase.GetLocalizedString(id)
            End Select
        End Function
    End Class
End Namespace