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

Exclude Columns from Column Chooser

Environment

Product Version 2019.1.220
Product RadGridView for WPF

Description

How to exclude columns from the column chooser in the control panel.

Solution

  1. Create an IValueConverter with your custom predicate to filter the columns.

    Example 1: Exclude the columns bound to the IsDeleted property from the column chooser

        public class ColumnsConverter : IValueConverter 
        { 
            public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
            { 
                var columns = value as Telerik.Windows.Controls.GridViewColumnCollection; 
                var filteredColumns = columns.OfType<GridViewBoundColumnBase>().Where(c => c.DataMemberBinding.Path.Path != "IsDeleted"); 
                return filteredColumns; 
            } 
     
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
            { 
                throw new NotImplementedException(); 
            } 
        } 
    
  2. Use the converter in the binding to the Columns property.

        <telerik:ControlPanelItem ButtonTooltip="Column chooser"> 
            <telerik:ControlPanelItem.ContentTemplate> 
                <DataTemplate> 
                    <DataTemplate.Resources> 
                        <local:ColumnsConverter x:Key="ColumnsConverter" /> 
                    </DataTemplate.Resources> 
                    <ListBox ItemsSource="{Binding Columns, Converter={StaticResource ColumnsConverter}}" BorderThickness="0"> 
                        <ListBox.ItemTemplate> 
                            <DataTemplate> 
                                <CheckBox Content="{Binding Header, Mode=OneWay}" IsChecked="{Binding IsVisible, Mode=TwoWay}" /> 
                            </DataTemplate> 
                        </ListBox.ItemTemplate> 
                    </ListBox> 
                </DataTemplate> 
            </telerik:ControlPanelItem.ContentTemplate> 
        </telerik:ControlPanelItem> 
    

    See Also

In this article