This is a migrated thread and some comments may be shown as answers.

Distinct filtering boolean with friendly names.

2 Answers 70 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Clint Singer
Top achievements
Rank 1
Clint Singer asked on 06 Nov 2009, 01:21 AM
Hi,

I have a column which is a boolean type.  When one clicks on the filter icon it gives the options, True and False, as is expected.   I replaced the True and False with some friendly names.  When I filter by these friendly names, the software crashes stating it doesn't know how to convert them to boolean types (as would be expected). 

I can trap the filtering event but I am not sure what I need to do next.  Do I need to modify the GridViewFilteringEventArgs?  An example would be appreciated.

Cheers,
Clint

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 06 Nov 2009, 10:15 AM
Hi Clint Singer,

You can use an IValueConverter in the Binding of your boolean column. The filtering UI will display the friendly names returned by the IValueConverter. Now, to retain the check-box appearance of the column I have defined its CellTemplate.

<UserControl x:Class="TicketID_256314_FriendlyDistinctValues.MainPage"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    xmlns:local="clr-namespace:TicketID_256314_FriendlyDistinctValues"
    xmlns:Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
  <Grid>
    <Grid.Resources>
      <local:NationalToFriendlyNameConverter x:Key="NationalToFriendlyNameConverter"/>
    </Grid.Resources>
    <telerik:RadGridView Name="playersGrid"
                         AutoGenerateColumns="False"
                         ColumnsWidthMode="Auto">
      <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Name"
                                    DataMemberBinding="{Binding Name}">
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="Number"
                                    DataMemberBinding="{Binding Number}">
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="Position"
                                    DataMemberBinding="{Binding Position}">
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="Country"
                                    DataMemberBinding="{Binding Country}">
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn Header="National"
                                    DataMemberBinding="{Binding National, Converter={StaticResource NationalToFriendlyNameConverter}}">
          <telerik:GridViewDataColumn.CellTemplate>
            <DataTemplate>
              <CheckBox IsChecked="{Binding National, Mode=TwoWay}" Controls:StyleManager.Theme="Office_Black"/>
            </DataTemplate>
          </telerik:GridViewDataColumn.CellTemplate>
        </telerik:GridViewDataColumn>
      </telerik:RadGridView.Columns>
    </telerik:RadGridView>
  </Grid>
</UserControl>

using System;
using System.Globalization;
using System.Windows.Data;
 
namespace TicketID_256314_FriendlyDistinctValues
{
    public class NationalToFriendlyNameConverter : IValueConverter
    {
        #region IValueConverter Members
 
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return ((bool) value) ? "National Player" : "Non-National Player";
        }
 
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
 
        #endregion
    }
}


I have attached the sample project. Please, let me know if this is not what you are after or if you have any other questions.

All the best,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Joe Brown
Top achievements
Rank 1
answered on 13 Mar 2011, 06:07 PM
This worked perfectly for once I changed the ((bool) value) to System.Convert.ToBoolean(value).  
It seems it could not unbox the value into a boolean with the cast that was originally coded.

Thanks for the help from this post !!
Tags
GridView
Asked by
Clint Singer
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Joe Brown
Top achievements
Rank 1
Share this question
or