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

Format DateTimeColumn does not work

9 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Markus
Top achievements
Rank 1
Markus asked on 25 Dec 2013, 05:32 PM
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

9 Answers, 1 is accepted

Sort by
0
George
Telerik team
answered on 26 Dec 2013, 08:30 AM
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 >>
0
Markus
Top achievements
Rank 1
answered on 26 Dec 2013, 03:32 PM
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
0
Accepted
George
Telerik team
answered on 27 Dec 2013, 09:02 AM
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 >>
0
Markus
Top achievements
Rank 1
answered on 27 Dec 2013, 11:49 PM
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
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Dec 2013, 03:44 PM
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 >>
0
Tanser
Top achievements
Rank 1
answered on 22 Jan 2014, 02:32 PM
I have same problem on my project. How did you solve this problem?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Jan 2014, 07:39 AM
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 >>
0
Scott
Top achievements
Rank 1
answered on 10 Feb 2017, 09:29 PM

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

Thanks.

-Scott

0
Dimitar
Telerik team
answered on 13 Feb 2017, 02:59 PM
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.
Tags
GridView
Asked by
Markus
Top achievements
Rank 1
Answers by
George
Telerik team
Markus
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Tanser
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or