GridViewDateTimeColumn formatString

7 posts, 0 answers
  1. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 16 Apr 2009 Link to this post

    Hi,

    Maybe a stupid question, but I was wondering if there is an overview of the different formatstrings you can use for the DateTime Column?

    I want to make a static function where I just need to call the right formatString, instead of every time searching the "net" for the right syntacs and add it.

    Thanks
  2. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 17 Apr 2009 Link to this post

    Hello Gerbrand,

    These are some samples of formatting DateTime column in RadGridView:

    GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];  
    column.DataTextFormatString = "{0:hh.mm.ss}";  //hour.minutes.seconds 
    column.DataTextFormatString = "{0:dd.MM.yy}";  //day.month.year 
    column.DataTextFormatString = "{0:hh.mm}";      //hour.minutes 
    column.DataTextFormatString = "{0:dd.MMMM.yy}";  //day.long month name.year 
    column.DataTextFormatString = "{0:dd-MM-yy}";  //day-month-year 
     

    You can find more information for DateTime formatting in MSDN.

    Greetings,
    Julian Benkov
    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. tuonglam
    tuonglam avatar
    3 posts
    Member since:
    Sep 2011

    Posted 09 Sep 2011 Link to this post

    I'm using like you say but i have a error.I'm using in Formload

    'Telerik.WinControls.UI.GridViewDateTimeColumn' does not contain a definition for 'DataTextFormatString' and no extension method 'DataTextFormatString' accepting a first argument of type 'Telerik.WinControls.UI.GridViewDateTimeColumn' could be found (are you missing a using directive or an assembly reference?)

    My code:

    GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];
     column.DataTextFormatString = "{dd-MM-yy}";  //day-month-year

    thank you very much!
  4. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 14 Sep 2011 Link to this post

    Hi Tuonglam,

    The code snippet provided by my colleague Julian concerned a version of RadControls for WinForms issued during 2009. If you are using one of the latest versions, you have to use the FormatString property as shown below:

    GridViewDateTimeColumn column = (GridViewDateTimeColumn)this.radGridView1.Columns["Date"];
    column.FormatString = "{0:hh.mm.ss}"//hour.minutes.seconds
    column.FormatString = "{0:dd.MM.yy}"//day.month.year
    column.FormatString = "{0:hh.mm}";      //hour.minutes
    column.FormatString = "{0:dd.MMMM.yy}"//day.long month name.year
    column.FormatString = "{0:dd-MM-yy}"//day-month-year

    I hope this helps.

    Greetings,
    Nikolay
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

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

    Posted 10 Feb in reply to Julian Benkov Link to this post

    How does this work if the SQL Server datatype is TimeSpan?

    Thank you.

    -Scott

  6. Dimitar
    Admin
    Dimitar avatar
    1877 posts

    Posted 13 Feb Link to this post

    Hi Scott,

    By default, the grid will create a GridViewTextBoxColumn, but you can replace the default text editor with the desired one in the EditorRequired event. Note that if the applied editor is not compatible with the TimeSpan value, it would be necessary to implement a Type Converter. A sample approach is demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types

    In addition, we have a feature request for this in our Feedback Portal. I have added a vote for it on your behalf. You can track its progress, subscribe for status changes and add your comment to it here.

    I hope this information is useful. Let me know if you need further assistance.

    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.
  7. Scott
    Scott avatar
    30 posts
    Member since:
    Dec 2015

    Posted 13 Feb in reply to Dimitar Link to this post

    Hi Dimitar-

    Thank you for the feature up vote and the interim guidance.

    -Scott

Back to Top