Localization of Filter for GridViewCheckBoxColumn

3 posts, 1 answers
  1. Dominik
    Dominik avatar
    38 posts
    Member since:
    Mar 2011

    Posted 30 Oct 2011 Link to this post

    Hi

    We use Silverlight 4 with the latest release of your great silverlight controls. We use the Gridview in combination with Ria-Services. I have now encountered a little problem with the filtering for the GridViewCheckBoxColumn column:

    1. When i filter the values in the column-> the texts in the filter (TRUE, FALSE) are in english and not in the language i need it to be (german, french). In other parts, the localization works fine.

    What can I do to make the localization work? Is there a way to set the texts explicitly from code (or make them disappear at all)?


    2. Furthermore, the filtering by default filters for distinct values that are present in the grid. However, using ria services in a paged grid, very often, there is only one value (true for example) in the grid, so we cannot filter for false.
    Is it possible to change that easily?


    Thanks in advance.

  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Nov 2011 Link to this post

    Hello Dominik,

    Actually, this would be the expected behavior since the distinct values in the filter are based on the underlying property. As it this case, they are boolean values - true and false - the distinct values display - true and false. 
    What you may try is to create a converter returning the translated strings, but still define your column as follows:

    <telerik:GridViewDataColumnDataMemberBinding="{Binding IsChampion, Converter={StaticResource MyConverter}}">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBoxIsChecked="{Binding IsChampion,Mode=TwoWay}"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>

    I am sending you a sample project illustrating the suggested approach.
    You could try to handle DistinctValuesLoading event of RadGridView. Please take a look at this article for reference on how you can use this event. 
    Let me know if you need any further assistance.
     

    Best wishes,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. Dominik
    Dominik avatar
    38 posts
    Member since:
    Mar 2011

    Posted 01 Nov 2011 Link to this post

    Hi

    Thanks for your help. That did it.
    Below the code I used:

    public class CustomGrid : RadGridView
        {
           
     private void CustomGridDistinctValuesLoading(object sender, GridViewDistinctValuesLoadingEventArgs e)
        {
            if(this.UsedDataSource!=null)
            {
                // Workaround to always display values for true and false (otherwise only values in list would be displayed->example: only true)
                    var trueFalseList = new List<bool>();
                    trueFalseList.Add(true);
                    trueFalseList.Add(false);
                    e.ItemsSource = trueFalseList;
     
            }
        }
     
    }
     
     
     
     public class BooleanToTextConverter : IValueConverter
        {
            public BooleanToTextConverter()
            {
                TrueString = "wahr";
                FalseString = "falsch";
            }
     
            private CustomCheckboxColumn _colum;
            public CustomCheckboxColumn Column
            {
                get { return _colum; }
                set { _colum = value; }
            }
     
            public string TrueString { get; set; }
            public string FalseString  { get; set; }
     
            public object Convert(
                object value,
                Type targetType,
                object parameter,
                CultureInfo culture)
            {
                bool toConvert = (bool)value;
                if (toConvert)
                {
                    return TrueString;
                }
                return FalseString;
            }
     
            public object ConvertBack(
                object value,
                Type targetType,
                object parameter,
                CultureInfo culture)
            {
                if (value is string)
                {
                    return ((string)value) == TrueString;
                }
                return false;
            }
     
        }
     
     
     
     public class CustomCheckboxColumn : GridViewCheckBoxColumn
        {
            public CustomCheckboxColumn()
                : base()
            {
                // do nothing (maybe include a better filter control some day)
            }
     
     
            protected override object GetCellContent(object item)
            {
                var toReturn = base.GetCellContent(item);
                if (toReturn is bool || toReturn is bool?)
                {
                    return toReturn;
                }
                var converter = DataMemberBinding.Converter as BooleanToTextConverter;
                if(converter!=null && toReturn is string)
                {
                    if(converter.TrueString == ((string)toReturn) )
                    {
                        return true;
                    }
                }
                return false;
            }
          
             
     
        }

Back to Top