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

GridView DateTime Column Editor Custom Format

5 Answers 552 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 18 Oct 2011, 06:25 AM
How do you change the default DateTime editor for a cell in a gridview date time column

I have tired using the DataEditFormatString, which according to the documentation is what you are supposed to use eg

gridView.Columns[5].DataEditFormatString = "{0:d}";

But it does not work.

5 Answers, 1 is accepted

Sort by
0
Alexander
Telerik team
answered on 20 Oct 2011, 09:25 AM
Hello Barry,

Thank you for reporting the obsolete help article. We will edit it in our next help update iteration. I have updated your Telerik points for your report.

You should use the CustomFormat property of GridViewDateTimeColumn instead of the obsolete DataEditFormatString:
((GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).CustomFormat = "d";

I hope it helps.

Best regards,
Alexander
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Barry
Top achievements
Rank 1
answered on 24 Oct 2011, 01:53 AM
The solution that you presented works, however, I have to use two statements to achieve the effect that I want: (which is not necessarily a problem in itself), but they require two different formats for the format string.

See the right and side of the following two lines of code:

rradGridView1.Columns["Date"].FormatString = "{0:d}";  //To set the default (non editing) format
(GridViewDateTimeColumn)this.radGridView1.Columns["Date"]).CustomFormat = "d";  //To set the editing format

It would seem to me to make more sense to use a consistent method of specifying the format string.

I guess that the logic behind the two formats is that for the display date a user could dress up the display with a format string like:

"The Due Date is: {0:d}"

But only the actual date should be displayed in the editor, as the date is the only editable part.

I think I have answered my own complaint/comment. But.....for people like me who have to get half way through a forum posting before realising why there may be two different styles of format strings, upgraded documentation that explains the above point with examples would be good to have.

Thanks
0
Alexander
Telerik team
answered on 24 Oct 2011, 11:02 AM
Hello Barry,

Thank you for writing back.

I agree that the RadGridView documentation should explain fully and clearly the mechanism for the control's data formatting. The FormatString property is universal for all RadGridView columns and is described in this help article. The GridViewDateTimeColumn's CustomFormat property is specific for GridViewDateTimeColumn and is added for more convenient formatting of the column's editor value. It should be explained in the GridViewDateTimeColumn's help article.

The GridViewDateTimeColumn's help article describes the general mechanism for formatting of the editors values - using the CellEditorInitialized event of RadGridView. This approach is suitable for all RadGridView column editors.

Kind regards,
Alexander
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Scott
Top achievements
Rank 1
answered on 10 Feb 2017, 09:23 PM

What would code be if I only want to show hours and minutes.  No seconds.  Something like hh:mm.

 

Thanks.

0
Dimitar
Telerik team
answered on 13 Feb 2017, 02:55 PM
Hi Scott,

The following article shows all format specifiers and how you can use them to create a custom format: Custom Date and Time Format Strings.

I hope this information is useful. 

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
Barry
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Barry
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or