8 Answers, 1 is accepted
I answered your support ticket on the same topic. I am pasting the answer here as well:
In order to change the date-time format in the RadDateTimeEditor itself, you should subscribe to the EditorRequired event. This event is fired whenever an editor is created and displayed. Then, in the event handler you can customize the date-time format by setting either the Format or the CustomFormat properties:
private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e) |
{ |
RadDateTimeEditor dateTimeEditor = e.Editor as RadDateTimeEditor; |
if (dateTimeEditor != null) |
{ |
((RadDateTimePickerElement)dateTimeEditor).Format = DateTimePickerFormat.Short; |
//or |
//dateTimeEditor.CustomFormat = "dd/mm/yyyy"; |
} |
} |
If you have additional questions, feel free to contact me.
Greetings,
Nikolay
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
void grd_EditorRequired(object sender, EditorRequiredEventArgs e) |
{ |
if (e.EditorType == typeof(RadDateTimeEditor)) |
{ |
if (grd.CurrentCell.FormatString == "{0:HH:mm}") |
{ |
((RadDateTimePickerElement)e.Editor).Format = DateTimePickerFormat.Custom; |
((RadDateTimePickerElement)e.Editor).CustomFormat = "HH:mm"; |
((RadDateTimePickerElement)e.Editor).ShowUpDown = true; //<--ERROR |
} |
else |
((RadDateTimePickerElement)e.Editor).Format = DateTimePickerFormat.Short; |
} |
if (e.EditorType == typeof(RadComboBoxEditor)) |
{ |
((RadComboBoxEditor)e.Editor).DropDownWidth = 180; |
} |
} |
If I comment out the line marked "ERROR" above, it works, however the calendar drops down when the user wants to enter the time.
The exact error, which happens when the user trys to edit the cell, looks like this:
{"Object reference not set to an instance of an object."} at Telerik.WinControls.UI.RadDateTimeEditor.EndInit() |
at Telerik.WinControls.UI.BaseGridBehavior.InitializeEditor(GridViewColumn column) |
at Telerik.WinControls.UI.BaseGridBehavior.OnMouseDownLeft(MouseEventArgs e) |
at Telerik.WinControls.UI.BaseGridBehavior.OnMouseDown(MouseEventArgs e) |
at Telerik.WinControls.UI.RadGridView.OnMouseDown(MouseEventArgs e) |
at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) |
Thanks for any assistance you can provide.
Thank you for writing.
I confirm that there is an issue if you try to change the default drop down button to a spin button. We will address it in some of the next releases. Currently, you can just remove the drop down button and in this way prevent showing the calendar when you want to edit only times. Please, review the code-block below:
private void radGridView1_EditorRequired(object sender, EditorRequiredEventArgs e) |
{ |
if (e.EditorType == typeof(RadDateTimeEditor)) |
{ |
((RadDateTimeEditor)e.Editor).CustomFormat = "HH:mm"; |
((RadArrowButtonElement)((RadDateTimeEditor)e.Editor).Children[1].Children[1]).Visibility = |
Telerik.WinControls.ElementVisibility.Hidden; |
} |
} |
I have updated your Telerik points for bringing our attention to this matter.
Please do not hesitate to contact me again if you have other questions.
All the best,
Martin Vasilev
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.
However the issue with the custom 24Hr format remains. I have StartDate, StartTime, EndDate, and EndTime columns - all RadDateTimePickers in my grid. You can see in the code I've provided that I'm checking the format string to see if it should be formatted as a time or date.
The problem I'm having is, once the user edits a time field in the grid, all the DateTime cells in the grid get formatted as time from then on. Should I not be using the current cell's format string? ... if (grd.CurrentCell.FormatString == "{0:HH:mm}")
if (grd.CurrentCell.FormatString == "{0:HH:mm}") |
{ |
((RadDateTimePickerElement)e.Editor).Format = DateTimePickerFormat.Custom; |
((RadDateTimePickerElement)e.Editor).CustomFormat = "HH:mm"; |
((RadArrowButtonElement)((RadDateTimeEditor)e.Editor).Children[1].Children[1]).Visibility = ElementVisibility.Hidden; |
} |
else |
{ |
((RadDateTimeEditor)e.Editor).CustomFormat = string.Empty; |
((RadDateTimePickerElement)e.Editor).Format = DateTimePickerFormat.Short; |
((RadArrowButtonElement)((RadDateTimeEditor)e.Editor).Children[1].Children[1]).Visibility = ElementVisibility.Visible; |
} |
Thanks.
How do Format Date Column in Edit Mode of the grid. I am using the WPF controls. I have to display the date values in 'dd/MM/yyyy' format in edit mode. I see there is no EditorRequiredEvent in case of WPF controls.So how do I change the format in these case?
My problem is when I click on the cell, the RadDateTimePicker considers the date as MM/dd/yyyy and it displays empty value. For example 13/05/2018 will show empty because 13 is not a valid month. So how to change this so that the it shows the required date format in Edit mode? Please help
I would like to note that this forum is related to the Telerik UI for WinForms suite. However, it seems that your question is related to WPF. Feel free to post your technical questions in the relevant forum: https://www.telerik.com/forums
Thus, the WPF's community will gladly assist you.
I hope this information helps.Regards,
Dess
Progress Telerik