This is a migrated thread and some comments may be shown as answers.

Using Custom datetime format with 'Quarter'

2 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
avishay
Top achievements
Rank 1
avishay asked on 12 May 2019, 02:05 PM

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 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 13 May 2019, 11:07 AM
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.
0
avishay
Top achievements
Rank 1
answered on 13 May 2019, 11:34 AM

Thanks a lot !!!

Now it's working good!!

Tags
GridView
Asked by
avishay
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
avishay
Top achievements
Rank 1
Share this question
or