SfDataGrid row header text/sensitivity table

Hi,

In the application I'm building I would like to have 2D sensitivity tables similar to the Excel Data/What if/Data Table. I thought I'd do these as a sfdatagrid with different values of one of the variables as the column headers and the values of  the other variable as the row headers. I would compute the various values of the result of interest in code-behind at runtime and populate the sfdatagrid. I can set static column headers in XAML using <syncfusion:GridTextColumn HeaderText="variable 1" />.

Row headers appear to be a bit more challenging. There's a number of Syncfusion forum answers etc showing how to set the sfdatagrid row headers to the row index number. For example, https://www.syncfusion.com/kb/5523/how-to-display-rowindex-at-rowheadercell-in-sfdatagrid.

There's also some solutions on  the WWW showing how to use databinding and RowHeaderTemplates to set the row headers. For example:

https://blog.magnusmontin.net/2014/08/18/right-aligned-row-numbers-datagridrowheader-wpf/

Is there a simple way to set Grid row header text in XAML similarly to setting GridTextColumn HeaderText?

Thanks

David

1 Reply

GT Gnanasownthari Thirugnanam Syncfusion Team February 28, 2018 06:08 PM UTC

Hi David, 

You can display the value in RowHeader by writing style to GridRowHeaderCell like below code example. 

<Window.Resources> 
        <local:RoHeaderConverter x:Key="rowHeaderConverter"/> 
        <Style TargetType="syncfusion:GridRowHeaderCell"> 
            <Setter Property="Template"> 
                <Setter.Value> 
                    <ControlTemplate TargetType="syncfusion:GridRowHeaderCell"> 
                        <Border x:Name="PART_RowHeaderCellBorder" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        BorderThickness="{TemplateBinding BorderThickness}"> 
                            <Grid> 
                                <TextBlock HorizontalAlignment="Center" 
                                   VerticalAlignment="Center" 
                                   Text="{Binding Converter={StaticResource rowHeaderConverter}}" 
                                   TextAlignment="Center" /> 
                            </Grid> 
                        </Border> 
                    </ControlTemplate>                    
                </Setter.Value> 
            </Setter> 
        </Style> 
</Window.Resources> 

public class RoHeaderConverter:IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
        //Here you can return the value for RowHeader 
        var orderInfo = value as OrderInfo; 
        return orderInfo.ShipCity.ToString(); 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
    { 
        throw new NotImplementedException(); 
    } 
} 

We have prepared the sample based on your requirement, you can download it from below mentioned location. 


Regards, 
Gnanasownthari T. 


Loader.
Up arrow icon