Datagrid DateTime column template

Jan 8, 2009 at 3:36 PM
Using a very simple WPF program (single window with a Toolkit Datagrid on it), I have a datatable (from an SQL query), which has some datetime type columns (birth date and such).

At present, the time is always displayed in MM/dd/yyyy hh:mm:ss format, I'd like it to be displayed in UK shortdate style (e.g dd/MM/yyyy).

My datagrid is simply bound to the table with no explicitly defined columns in the XAML code.
<dg:DataGrid Name="dataGrid1" />

with the line in my '.cs' file of

dataGrid1.ItemsSource = resultTable.DefaultView;

to bind / create the respective columns.

I have scoured google and cannot find any info on how I can override the date mask, or even programmatically override the template for the datagrid columns.

Ideally, I would like to build the datagrid columns dynamically and set up the template structure, but if I try to build the columns, I end up with double the amount of columns as it still seems to add the original table. If I remove the Itemsource setting line, I end up with column headers, but no data.  Everything I've seen so far assumes the columns are 'hard-coded' within the XAML but asI am looking to create a generic view which can be called for various tables and column combinations, where column header templates and column tpye templates could be set up based on the resulttable structure.

If anyone can shed any light on this I would be most grateful,  I am presuming of course, control of column templates can be handled at the code level.
Jan 9, 2009 at 3:28 PM
Found out how to do it eventually, not exactly obvious but at least now *I* know how to do it.
Jan 12, 2009 at 10:01 PM
Can you please post your solution, I've got the same issue here. All I can do is to format every column by myself. I wondered if you have any better solution.
Jan 13, 2009 at 8:31 AM
When you say you had to format each column, do you mean explicitly or in a dynamically handled loop?
My solution basically involved determining the column type then creating a templated column for datetime fields from the datatable.
If you're having to do it explicitly in XAML or naming columns directly then my solution may be of help.

The goal was to allow me to create an advanced view which we could utilise in a generic "search" window regardless of the table and fields used, pretty sure I've nailed it but needs more testing.