Category / Section
How to change the row and column header values?
1 min read
You can change the value of row and column header by using the TemplateCell property of OLAP Grid and converters.
XAML
<UserControl.Resources> <Utils:TextConverter x:Key="textConverter"></Utils:TextConverter> <Style x:Key="colStyle" TargetType="syncfusion:OlapGridTemplateCell"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="syncfusion:OlapGridTemplateCell"> <StackPanel Grid.Column="1" Orientation="Horizontal" Background="#4A88C6"> <!--Text block--> <TextBlock Grid.Column="1" Margin="3,4,4,0" Text="{Binding Converter={StaticResource textConverter}}" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="Calibri" FontSize="12" MinWidth="75" /> </StackPanel> </ControlTemplate> </Setter.Value> </Setter> </Style> </UserControl.Resources> <syncfusion:OlapGrid Height="400" x:Name="olapGrid" FreezeHeaders="True" VisualStyle="Office2007Blue" OlapDataManager="{Binding OlapDataManager}" > <syncfusion:OlapGrid.ColumnHeaderStyle> <syncfusion:OlapGridCellStyle Style="{StaticResource colStyle}"/> </syncfusion:OlapGrid.ColumnHeaderStyle> </syncfusion:OlapGrid>
C#
public class TextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string text = null; PivotCellDescriptor cellinfo = value as PivotCellDescriptor; if (cellinfo != null) { switch (cellinfo.CellValue) { case "Australia": text = "Aus"; return text; case "Canada": text="Can"; return text; case "France": text = "Fran"; return text; case "Germany": text = "Ger"; return text; case "United Kingdom": text = "UK"; return text; case "United States": text = "US"; return text; } } return text; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
VB
Public Class TextConverter Implements IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Dim text As String = Nothing Dim cellinfo As PivotCellDescriptor = value as PivotCellDescriptor If Not cellinfo Is Nothing Then Select Case cellinfo.CellValue Case "Australia" text = "Aus" Return text Case "Canada" text = "Can" Return text Case "France" text = "Fran" Return text Case "Germany" text = "Ger" Return text Case "United Kingdom" text = "UK" Return text Case "United States" text = "US" Return text End Select End If Return text End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Throw New NotImplementedException() End Function End Class