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

Programmatic filtering of a DateTime column using another Culture

1 Answer 303 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ITC
Top achievements
Rank 1
ITC asked on 15 Feb 2018, 01:30 PM

I'm not able to use german date format to filter my grid.

I've got a project that is set to german culture using

var Culture = new CultureInfo("de-DE");
//Culture.DateTimeFormat = DateTimeFormatInfo.CurrentInfo; // No effect on datetime parsing
Thread.CurrentThread.CurrentCulture = Culture;
Thread.CurrentThread.CurrentUICulture = Culture;

This is done in App.cs. Interestingly enough these options alone don't change the language of the grid, I have to add the following to my window:

this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);

 

So now the grid's in german and I'm trying to filter the Column "DateTime". After adding the data I'm using this code:

MyGrid.FilterDescriptors.Add(new Telerik.Windows.Data.FilterDescriptor("DateTime", Windows.Data.FilterOperator.IsEqualTo, "31.01.2018"));

 

Which throws an exception because obviously the Date "31.01.2018" can not be parsed.

Funny: Switching the month and day (without changing periods to slashes) works:

MyGrid.FilterDescriptors.Add(new Telerik.Windows.Data.FilterDescriptor("DateTime", Windows.Data.FilterOperator.IsEqualTo, "01.31.2018"));

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 20 Feb 2018, 01:10 PM
Hello Rolf,

I answered your question in ticket with ID: 1153638. Here is some information if someone else has the same scenario.

Setting the Language in order for the RadGridView to respect the current culture settings is one alternative . Another is to set the IsLocalizationLanguageRespected property of the RadGridView to False. This is documented in the CurrentCulture Format Settings are not respected article in our documentation. 

As for the filtering, when a RadGridView column is bound to an object of type DateTime, when filtering, you have to pass a DateTime object to the FilterDescriptor in order to filter the control correctly. You can do that like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string dateString = "31.01.2018";
  
            var dateTime = DateTime.Parse(dateString, Thread.CurrentThread.CurrentCulture);
            MyGrid.FilterDescriptors.Add(new Telerik.Windows.Data.FilterDescriptor("DateTime", Windows.Data.FilterOperator.IsEqualTo, dateTime));
        }
 
Regards,
Vladimir Stoyanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
ITC
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or