views:

964

answers:

1

We're using a WPF GridView that is dynamically bound to a DataTable (which in turn is the direct result of a DB query). This basically works fine and displays whatever the results from the DB query are in a nice table.

Now the problem is that some of the results contain DateTime columns, and the date displayed is always in US format and not in the user specified date format.

Is there an easy way to set the datetime formatting for the GridView display?

We don't know beforehand which columns will be DateTime as there are a number of different tables that are displayed.

The way we fill the gridview is as follows:

        MyListView.DataContext = data;
        MyListView.SetBinding(ListView.ItemsSourceProperty, new Binding());
        MyGridView.Columns.Clear();

        foreach (DataColumn col in data.Columns)
        {
            GridViewColumn gvcol = new GridViewColumn();
            gvcol.Header = col.ColumnName;
            gvcol.DisplayMemberBinding = new Binding(col.ColumnName);
            MyGridView.Columns.Add(gvcol);
        }
+1  A: 

It should be enough to put the current culture in the applucation startup

/// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

        }
    }
Jonke
thanks for the quick reply, this works! now is there also a way to set this later in the application, after showing a login screen, and then setting it not depending on the system language but on a per-user stored language that is returned after login?
Tom
additionaly to the above solution: is there a solution to change the date formatting specifically for the GridView?
Tom