Using Custom datetime format with 'Quarter'

3 posts, 0 answers
  1. avishay
    avishay avatar
    3 posts
    Member since:
    May 2019

    Posted 12 May 2019 Link to this post

    I'm trying to alter a datetime column in my radgridview object.

    I need it to be shown as followed:

    <Year  Quarter of year>

    For example the dateTime value of" '28/5/2012' shold be shown as: '2012  Q2'.

    I undetstand that i need to changed it with a custmize FormatProvider and also to edit the values of the cells in radgridView1_CellFormating.

    I  also declared the custmize FormatProvider.

    But how do I connect that formatProvider to that specific dateTime column ?

    Thanks!

  2. Dimitar
    Admin
    Dimitar avatar
    2907 posts

    Posted 13 May 2019 Link to this post

    Hello Avishay,

    If you need to edit the data you can create a type converter and attach it to the column. An example is available here: Converting Data Types. If you only need to show this you can use the CellFormatting event and set the text of the cell. Here is an example for this:
    private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.Column.Name == "Date" && e.Row is GridViewDataRowInfo)
        {
            var value = (DateTime)e.CellElement.Value;
            e.CellElement.Text = value.Year + " Q" + (value.Month + 2) / 3;
     
        }
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. avishay
    avishay avatar
    3 posts
    Member since:
    May 2019

    Posted 13 May 2019 Link to this post

    Thanks a lot !!!

    Now it's working good!!

Back to Top