Culture of data in GridView

5 posts, 1 answers
  1. Patrick
    Patrick avatar
    498 posts
    Member since:
    Aug 2012

    Posted 05 Nov 2012 Link to this post

    Hello,
    with the previous version (.912) of RadGridView, it was easy to change the culture of the application: a single call to
    Thread.CurrentThread.CurrentCulture = new CultureInfo("xxx");
    changes the culture for the whole application.
    In the last version (.1017), it seems that now the formatting is made in another thread and that the culture is no more taken into account!

    If you create a new Silverlight 5 application and

    Create a new class MyData.cs with:
    using System;
     
    namespace RadControlsSilverlightApp1
    {
      public class MyData
      {
        public DateTime DateTime {get; set;}
      }
    }

    Replace MainPage.xaml.cs with:
    using System;
    using System.Globalization;
    using System.Threading;
    using System.Windows.Controls;
     
    namespace RadControlsSilverlightApp1
    {
      public partial class MainPage : UserControl
      {
        public MainPage()
        {
          InitializeComponent();
          Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-fr");
     
          var Data = new MyData[100];
          var DT   = DateTime.Now;
          var Rnd  = new Random();
          for (Int32 ix = 0; ix < 100; ix++)
          {
            Data[ix] = new MyData () {DateTime = DT};
            DT = DT.AddSeconds(Rnd.Next(60 * 60 * 24));
          }
     
          GridView.ItemsSource = Data;
        }
      }
    }

    and MainPage.xaml with:
    <UserControl
      x:Class="RadControlsSilverlightApp1.MainPage"
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
        <Grid Margin="5">
       <telerik:RadGridView Name="GridView"
                            AutoGenerateColumns="False">
         <telerik:RadGridView.Columns>
           <telerik:GridViewDataColumn DataFormatString="G"
                                       DataMemberBinding="{Binding DateTime}"
                                       Header="Date"
                                       Width="150" />
         </telerik:RadGridView.Columns>
       </telerik:RadGridView>
        </Grid>
    </UserControl>

    Now, run the application and see that the dates are still displayed in US format!

    Patrick
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Nov 2012 Link to this post

    Hi,

    Thank you for the detailed description. You could check this forum thread where a similar question is discussed.

    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Patrick
    Patrick avatar
    498 posts
    Member since:
    Aug 2012

    Posted 05 Nov 2012 Link to this post

    Didie,
    it doesnt't work the same in Silverlight, but I've got it.
    In App.xaml.cs, you must add:
    ((FrameworkElement) RootVisual).Language = XmlLanguage.GetLanguage ("<LanguageCode>");
    After setting the RootVisual property.

    But, if you had take a default value of Thread.CurrentThread.CurrentCulture for Language, no application would be broken.

    Patrick
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Nov 2012 Link to this post

    Hi,

    You could as well check this troubleshooting article. The behaviour is like so as we have tried to be consistent with the DataGrid. 

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Feb 2013 Link to this post

    Hello,

    In addition to my last answer, I would like to inform you that we have introduced a new property IsLocalizationLanguageRespected of the RadGridView especially for such cases. It is available in our latest internal build. 

    Its default value is 'true' meaning that the formatting will be based on the Language property (default behaviour). Once you set it to 'false", then the CurrentCulture will be respected. 
     

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top