Null dates - DateFormatString

10 posts, 1 answers
  1. Chris
    Chris avatar
    53 posts
    Member since:
    Oct 2012

    Posted 03 May 2009 Link to this post

    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
  2. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 05 May 2009 Link to this post

    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.
  3. DevCraft banner
  4. Chris
    Chris avatar
    53 posts
    Member since:
    Oct 2012

    Posted 08 May 2009 Link to this post

    Many thanks for the reply Pavel.
  5. Alfa
    Alfa avatar
    34 posts
    Member since:
    May 2005

    Posted 20 Nov 2009 Link to this post

    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

  6. Alfa
    Alfa avatar
    34 posts
    Member since:
    May 2005

    Posted 22 Nov 2009 Link to this post

    I got the fix.

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

    Rdgs
    Alfa
  7. Bill Jindrich
    Bill Jindrich avatar
    11 posts
    Member since:
    Dec 2009

    Posted 01 Dec 2009 Link to this post

    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!

     

     

     

     

     

     

  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Dec 2009 Link to this post

    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.
  9. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 22 Jun 2011 Link to this post

    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>
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 23 Jun 2011 Link to this post

    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
  11. Macrel
    Macrel avatar
    32 posts
    Member since:
    Aug 2008

    Posted 10 Apr 2013 Link to this post

    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>
Back to Top
DevCraft banner