Texbox in datagrid not displaying corrent Date Format

May 12, 2009 at 1:37 PM

ok I have a datagrid and needed a DatePicker in one of the columns. I found an example online and created the following

<Custom:DataGridTemplateColumn Header="REQUIRED">
                                <Custom:DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <Custom:DatePicker SelectedDate="{Binding Path=REQUIRED}"/>
                                    </DataTemplate>
                                </Custom:DataGridTemplateColumn.CellEditingTemplate>
                                <Custom:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock Text="{Binding Path=REQUIRED, StringFormat='d'}"/>
                                    </DataTemplate>
                                </Custom:DataGridTemplateColumn.CellTemplate>
                            </Custom:DataGridTemplateColumn>

When the grid first displays the textbox's have the date displayed as dd/MM/yyyy which is as I want but if I change the date the textbox now displays the date as dd/MM/yyy hh:mm tt

example 12/05/2009 turns to 12/05/2009 12:50 PM when editing the date with DatePicker.

Is there away to keep the format of the date as dd/MM/yyy ?

Coordinator
May 12, 2009 at 9:56 PM

Hi Gaz83, This is by design but you can work around it by writing your own converter and truncating the string (to remove the hrs and mins).  Hope that helps!

May 14, 2009 at 4:49 PM

Cheers for that I have its sorted.

I have another 2 questions

Firs my new xmal code

<Custom:DataGridTemplateColumn Header="REQUIRED">
                                <Custom:DataGridTemplateColumn.CellEditingTemplate>
                                    <DataTemplate>
                                        <Custom:DatePicker x:Name="G10EDate" SelectedDate="{Binding Path=REQUIRED}" />
                                    </DataTemplate>
                                </Custom:DataGridTemplateColumn.CellEditingTemplate>
                                <Custom:DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <TextBlock x:Name="G10EDate" Text="{Binding Path=REQUIRED, Converter={StaticResource myDateConverter}, Mode=TwoWay}" />
                                    </DataTemplate>
                                </Custom:DataGridTemplateColumn.CellTemplate>
                            </Custom:DataGridTemplateColumn>

1) I have set the Mode for the TextBlock to twoWay will this mean that as I change the date, the date will change in the DataTable the DataGrid is linked too?

2)Why is it that some of the DatePickers have the date in and some have "Show Calender"?