New to Telerik UI for WPF? Download free 30-day trial

Display CheckBox in Merged Cell for Column Bound to Boolean Property

Environment

Product RadGridView for WPF

Description

How to show a CheckBox in merged cells inside a column bound to a boolean property (By default, True/False is shown).

Solution

Create a MergedCellsStyleSelector and return a custom style targeting GridViewMergedCell with its ContentTemplate containing a CheckBox. You can return this style only when the Value of the MergedCellInfo is of type bool.

<Grid> 
    <Grid.Resources> 
        <DataTemplate x:Key="CheckBoxContentTemplate"> 
            <CheckBox IsChecked="{Binding .}" IsHitTestVisible="False"/> 
        </DataTemplate> 
 
        <Style x:Key="CheckBoxMergedCellStyle" TargetType="telerik:GridViewMergedCell" BasedOn="{StaticResource GridViewMergedCellStyle}"> 
            <Setter Property="ContentTemplate" Value="{StaticResource CheckBoxContentTemplate}" /> 
        </Style> 
 
        <local:MergedCellsStyleSelector x:Key="MergedCellStyleSelector" CheckBoxStyle="{StaticResource CheckBoxMergedCellStyle}"/> 
    </Grid.Resources> 
    <telerik:RadGridView x:Name="radGridView" 
                         MergedCellsDirection="Vertical"   
                         GroupRenderMode="Flat" 
                         EditTriggers="CellClick" 
                         MergedCellsStyleSelector="{StaticResource MergedCellStyleSelector}"> 
    </telerik:RadGridView> 
</Grid> 

public class MergedCellsStyleSelector : StyleSelector 
{ 
    public Style CheckBoxStyle { get; set; } 
 
    public override Style SelectStyle(object item, DependencyObject container) 
    { 
        var cellInfo = item as MergedCellInfo; 
 
        if(cellInfo.Value.GetType() == typeof(bool)) 
        { 
            return CheckBoxStyle; 
        } 
 
        return base.SelectStyle(item, container); 
    } 
} 
In this article