Format DateTimeColumn does not work

10 posts, 1 answers
  1. Markus
    Markus avatar
    12 posts
    Member since:
    May 2013

    Posted 25 Dec 2013 Link to this post

    Hi everbody,

    I'm trying to format a bound DateTimeColumn to show only the short dateformat without the time. I have tried everything, but it does not work.

    I tried:

    Format = Short and Custom
    FormatString = {0:d}
    FormatString = d


    I read the online documentation but it does not work. Does anyone have a solution for this?

    Thank you very much and have a nice christmas!

    Markus
  2. George
    Admin
    George avatar
    500 posts

    Posted 26 Dec 2013 Link to this post

    Hello Markus,

    Thank you for contacting us.

    The Format property of the GridViewDateTimeColumn is used to format the value of the editor which is initialized when you want to edit a cell's value (more information about editors - Editors). If you want to change the format string of the displayed value, when not in edit mode you need to change the FormatString property. For example in order to set the format string to Short format you can use the following code:
    col.FormatString = "{0:MM/dd//yyyy}";

    I have also attached a sample project which demonstrates this functionality.

    I hope this helps. 

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Markus
    Markus avatar
    12 posts
    Member since:
    May 2013

    Posted 26 Dec 2013 Link to this post

    Hi George,

    thank you for your answer. In the example it works fine. But my grid is bound to a BindingList and in Bound-Mode, the RadGridView is ignoring all the set format-attributes.

    The GridViewDateTimeColumn straightly ignores the format properties.

    Markus
  4. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 27 Dec 2013 Link to this post

    Hi Markus,

    Thank you for writing back.

    I have modified the project I provided you with in the previous reply in a way that the grid is bound to a collection of objects which have a property of type DateTime, however it still seems that the FormatString property is working fine.

    Please, find the attached project below. Let me know if the problem still exists in your application and if it does let me know how to reproduce it in my application or provide me one of your own.

    Looking forward to your response.

    Regards,
    George
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  5. Markus
    Markus avatar
    12 posts
    Member since:
    May 2013

    Posted 27 Dec 2013 Link to this post

    Hi George,

    I found out the problem in my application. The source was the loaded gridlayout.
    Thank you very much for your quick help.

    Best regards

    Markus
  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4081 posts

    Posted 30 Dec 2013 Link to this post

    Hello Markus,

    Thank you for writing back.

    I am glad that the issue you were facing is now resolved. However, have in mind that GridViewDateTimeColumn.FormatString property determines how to display the cell text when not in edit mode.

    Do not hesitate to contact us if you have any additional questions.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  7. Tanser
    Tanser avatar
    10 posts
    Member since:
    Nov 2013

    Posted 22 Jan 2014 Link to this post

    I have same problem on my project. How did you solve this problem?
  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    4081 posts

    Posted 27 Jan 2014 Link to this post

    Hello Tanser,

    Thank you for contacting Telerik Support.
     
    The GridViewDateTimeColumn.FormatString property sets the format of the date, when the cell is not currently being edited. The CustomFormat property is used to format the date once the user clicks on the cell to invoke the editor.
    Our GridViewDateTimeColumn help article is quite useful about this topic. Here is just a sample code snippet:
    GridViewDateTimeColumn dateTimeColumn = new GridViewDateTimeColumn("DateTimeColumn");
     
    //datetime format when not in edit mode
    dateTimeColumn.FormatString = "{0:MM/dd//yyyy}";
     
    //datetimeformat when in edit mode
    dateTimeColumn.Format = DateTimePickerFormat.Custom;
    dateTimeColumn.CustomFormat = "MM/dd";
     
    this.radGridView1.Columns.Add(dateTimeColumn);

    If you experience any difficulties related to the date formatting, please provide your sample code. Thus, we would be able to investigate the precise case and suggest an appropriate solution.

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  9. Scott
    Scott avatar
    36 posts
    Member since:
    Dec 2015

    Posted 10 Feb 2017 Link to this post

    What would the code be if I only wanted to show hours and minutes only?  No seconds.

    Thanks.

    -Scott

  10. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 13 Feb 2017 Link to this post

    Hi Scott,

    Here is an example:
    GridViewDateTimeColumn dateTimeColumn =  radGridView1.Columns["Date"]as GridViewDateTimeColumn;
     
    //datetime format when not in edit mode
    dateTimeColumn.FormatString = "{0:HH/mm}";
     
    //datetimeformat when in edit mode
    dateTimeColumn.Format = DateTimePickerFormat.Custom;
    dateTimeColumn.CustomFormat = "HH/mm";

    Should you have any other questions do not hesitate to ask.

    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