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

Null dates - DateFormatString

9 Answers 288 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 03 May 2009, 05:49 PM
Is there a way to set up the grid to display a blank cell for null dates.  Since my grid is bound to an observablecollection and the date is a DateTime (hence a null date become 01/01/0001), using DataFormatString="{}{0:d}" gives me the date as 01/01/0001. 

I would like this field to be blank. 

Thanks in advance

Chris

9 Answers, 1 is accepted

Sort by
0
Accepted
Pavel Pavlov
Telerik team
answered on 05 May 2009, 01:23 PM
Hello Chris,

The sample project attached demonstrates how to achieve this using a custom value converter.
In the binding of the column we specify our converter. Then in the Convert method we check if the date is "null ". There is the place where you can do your custom formatting as well as I am not sure the column format string will still  work with this approach.

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Chris
Top achievements
Rank 1
answered on 08 May 2009, 03:17 PM
Many thanks for the reply Pavel.
0
Alfa
Top achievements
Rank 1
answered on 20 Nov 2009, 11:37 AM
Hi,

I implement the solution in Q3 2009 release.
Everything works fine but now it is not letting me go out of cell without entering a valid date.
It is showing "Input is not in correct format" error message when i try to leave it blank.

Any fix?

Rgds
Alfa

0
Alfa
Top achievements
Rank 1
answered on 23 Nov 2009, 05:23 AM
I got the fix.

Stupid mistake of not converting null value in in DateTimeFormat in ConvertBack method was the issue.

Rdgs
Alfa
0
Bill Jindrich
Top achievements
Rank 1
answered on 01 Dec 2009, 11:43 PM
Hi All,
I downloaded the sample ZIPped project and I see it working as desired. My problem is that my data is coming from a list of loaded objects that contain a number of properties (and my grid has a number of columns, each displaying a property). I can't figure out the syntax to use in either the .XAML or the .XAML.VB file in my project to associate the DateConverter with the date column. Here's a snippet of my current .XAML:
...

 

 

<telerikGridView:RadGridView.Columns>

 

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding origin}" Header="" />

 

 

 

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding title}" Header="Title" TextWrapping="Wrap" />

 

 

 

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding dueDate}" Header="Due Date" DataFormatString="{}{0:dd/MM/yyyy}" TextWrapping="Wrap" />

 

 

 

 

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding delivery}" Header="Delivery" TextWrapping="Wrap"/>

 

 

 

 

<telerikGridView:GridViewDataColumn DataMemberBinding="{Binding duration}" Header="Duration" TextWrapping="Wrap"/>

 

 

 

 

 

 

...

When I look in the sample project, I see:
 ...
<
telerik:RadGridView.Columns>

 

 

 

 

 

 

<telerik:GridViewDataColumn DataMemberBinding="{Binding Converter={StaticResource MyDateConverter}}" HeaderText="Date" />

 

 

 

 

</telerik:RadGridView.Columns>
...
My challenge: what is the syntax that allows my to associate the DateConverter class, as above, with my date column that is bound to the dueDate property, keeping the dueDate property associated with the column, as well.

thanks in advance!

 

 

 

 

 

 

0
Vlad
Telerik team
answered on 02 Dec 2009, 06:53 AM
Hi,

Here is an example:

<telerik:GridViewDataColumn DataMemberBinding="{Binding dueDate, Converter={StaticResource MyDateConverter}}"  />

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
danparker276
Top achievements
Rank 2
answered on 23 Jun 2011, 12:01 AM
The converter won't work with the aggregate function though right?  There's no easy way around this.


                        <telerik:GridViewDataColumn.AggregateFunctions>
                            <telerik:MinFunction ResultFormatString="{}First: {0:d}" SourceField="Date" />
                            <telerik:MaxFunction ResultFormatString="{}Last: {0:d}" SourceField="Date" />
                        </telerik:GridViewDataColumn.AggregateFunctions>
0
Vlad
Telerik team
answered on 23 Jun 2011, 07:00 AM
Hi,

You can apply converter to the Binding in your custom footer/group footer. Please check this demo for more info how to define custom footers. 

All the best,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marcel
Top achievements
Rank 1
answered on 10 Apr 2013, 03:42 PM
This also helped - from http://www.telerik.com/community/forums/silverlight/gridview/converter-staticresource-myconverter-in-c.aspx
<Grid.Resources>
  <local:MyConverter x:Key="myDataConverter" />
</Grid.Resources>
 
<telerik:GridViewDataColumn Header="Discontinued" DataMemberBinding="{Binding Discontinued}">
<telerik:GridViewDataColumn.CellTemplate>
 <DataTemplate>
    <TextBlock Text="{Binding Discontinued, Converter={StaticResource myConverter}}" />
</DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Chris
Top achievements
Rank 1
Alfa
Top achievements
Rank 1
Bill Jindrich
Top achievements
Rank 1
Vlad
Telerik team
danparker276
Top achievements
Rank 2
Marcel
Top achievements
Rank 1
Share this question
or