GridView DateTime Column Editor Custom Format

6 posts, 0 answers
  1. Barry
    Barry avatar
    18 posts
    Member since:
    Jul 2008

    Posted 18 Oct 2011 Link to this post

    How do you change the default DateTime editor for a cell in a gridview date time column

    I have tired using the DataEditFormatString, which according to the documentation is what you are supposed to use eg

    gridView.Columns[5].DataEditFormatString = "{0:d}";

    But it does not work.
  2. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 20 Oct 2011 Link to this post

    Hello Barry,

    Thank you for reporting the obsolete help article. We will edit it in our next help update iteration. I have updated your Telerik points for your report.

    You should use the CustomFormat property of GridViewDateTimeColumn instead of the obsolete DataEditFormatString:
    ((GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).CustomFormat = "d";

    I hope it helps.

    Best regards,
    Alexander
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. Barry
    Barry avatar
    18 posts
    Member since:
    Jul 2008

    Posted 23 Oct 2011 Link to this post

    The solution that you presented works, however, I have to use two statements to achieve the effect that I want: (which is not necessarily a problem in itself), but they require two different formats for the format string.

    See the right and side of the following two lines of code:

    rradGridView1.Columns["Date"].FormatString = "{0:d}";  //To set the default (non editing) format
    (GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).CustomFormat = "d";  //To set the editing format

    It would seem to me to make more sense to use a consistent method of specifying the format string.

    I guess that the logic behind the two formats is that for the display date a user could dress up the display with a format string like:

    "The Due Date is: {0:d}"

    But only the actual date should be displayed in the editor, as the date is the only editable part.

    I think I have answered my own complaint/comment. But.....for people like me who have to get half way through a forum posting before realising why there may be two different styles of format strings, upgraded documentation that explains the above point with examples would be good to have.

    Thanks
  4. Alexander
    Admin
    Alexander avatar
    306 posts

    Posted 24 Oct 2011 Link to this post

    Hello Barry,

    Thank you for writing back.

    I agree that the RadGridView documentation should explain fully and clearly the mechanism for the control's data formatting. The FormatString property is universal for all RadGridView columns and is described in this help article. The GridViewDateTimeColumn's CustomFormat property is specific for GridViewDateTimeColumn and is added for more convenient formatting of the column's editor value. It should be explained in the GridViewDateTimeColumn's help article.

    The GridViewDateTimeColumn's help article describes the general mechanism for formatting of the editors values - using the CellEditorInitialized event of RadGridView. This approach is suitable for all RadGridView column editors.

    Kind regards,
    Alexander
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  5. Scott
    Scott avatar
    36 posts
    Member since:
    Dec 2015

    Posted 10 Feb 2017 Link to this post

    What would code be if I only want to show hours and minutes.  No seconds.  Something like hh:mm.

     

    Thanks.

  6. Dimitar
    Admin
    Dimitar avatar
    2951 posts

    Posted 13 Feb 2017 Link to this post

    Hi Scott,

    The following article shows all format specifiers and how you can use them to create a custom format: Custom Date and Time Format Strings.

    I hope this information is useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top