I found multiple requests back in 2009 for this feature and it appears it has been implemented.
According to this page, the DateTimePicker does have the ability to show both dates and times to choose.
https://www.telerik.com/products/winforms/datetimepicker.aspx
The page is marked as UI for Winforms and I have been trying to find out how to make the DateTimePicker to show both dates and times.
There is no code for it and no articles. This is for winforms.
Is this even possible?
Thanks.
8 Answers, 1 is accepted
Hello, Tim,
In order to show the time part in the drop down, it is necessary to set the ShowTimePicker property to true.
Please refer to the following code snippet demonstrating how to setup RadDateTimePicker in order to show date and time part in the popup calendar:
this.radDateTimePicker1.Format = DateTimePickerFormat.Custom;
this.radDateTimePicker1.CustomFormat = "dd/MM/yyyy hh:mm";
this.radDateTimePicker1.DateTimePickerElement.ShowTimePicker = true;
this.radDateTimePicker1.DateTimePickerElement.CalendarSize = new Size(400, 300);
I hope this information helps. If you need any further assistance please don't hesitate to contact me.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Thanks for the info, it worked.
Is it possible to do the same with a GridViewDateTimeColumn?
In the RadGridView.CellEditorInitialized event you have access to the editor. Thus, you can apply the same properties to the RadDateTimeEditorElement:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor!=null)
{
RadDateTimeEditorElement el = editor.EditorElement as RadDateTimeEditorElement;
el.Format = DateTimePickerFormat.Custom;
el.CustomFormat = "dd/MM/yyyy hh:mm";
el.ShowTimePicker = true;
el.CalendarSize = new Size(400, 300);
}
}
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Thanks again. I did find this information and it works. Now for one more question.
I'm trying to capture the Close button event on the calendar so it will update the database without leaving the cell.
I can capture it on the CellEndEdit or CellValueChanged but the user will have to leave the cell.
I found possibly a mouse_down event handler to add to the calendar but am having trouble adding it and finding the close button.
Maybe you can point me into the right direction?
Thanks again.
You can subscribe to the RadDateTimePickerCalendar.TimePicker.CloseButtonClicked event in order to detect when the Close button is clicked:
private void radGridView1_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
RadDateTimeEditor editor = e.ActiveEditor as RadDateTimeEditor;
if (editor != null)
{
RadDateTimeEditorElement el = editor.EditorElement as RadDateTimeEditorElement;
el.Format = DateTimePickerFormat.Custom;
el.CustomFormat = "dd/MM/yyyy hh:mm";
el.ShowTimePicker = true;
el.CalendarSize = new Size(400, 300);
el.Calendar.ShowFooter = true;
RadDateTimePickerCalendar calendarBehavior = el.GetCurrentBehavior() as RadDateTimePickerCalendar;
calendarBehavior.TimePicker.CloseButtonClicked -= TimePicker_CloseButtonClicked;
calendarBehavior.TimePicker.CloseButtonClicked += TimePicker_CloseButtonClicked;
}
}
private void TimePicker_CloseButtonClicked(object sender, EventArgs e)
{
}
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Thanks but the CloseButtonClicked property is not available.
I'm proficient in C# and actually prefer it but in this project we are using VB.
Here's the code that does not have the CloseButtonClicked property...
Private Sub dgProduction_CellEditorInitialized(sender As Object, e As GridViewCellEventArgs) Handles dgProduction.CellEditorInitialized
Dim editor As RadDateTimeEditor = TryCast(e.ActiveEditor, RadDateTimeEditor)
If editor IsNot Nothing Then
Dim element As RadDateTimeEditorElement = TryCast(editor.EditorElement, RadDateTimeEditorElement)
element.CalendarSize = New System.Drawing.Size(400, 300)
element.ShowTimePicker = True
element.TextBoxElement.EnableMouseWheel = False
Dim calendarBehavior As RadDateTimePickerCalendar = TryCast(element.GetCurrentBehavior(), RadDateTimePickerCalendar)
'No CloseButtonClicked available here
'calendarBehavior.TimePicker.
End If
End Sub
Never mind, it wasn't in the intellisense but it works.
Thanks!!!
Hello, Tim
Here is the relevant VB.NET code snippet: Private Sub RadGridView1_CellEditorInitialized(sender As Object, e As Telerik.WinControls.UI.GridViewCellEventArgs)
Dim editor As RadDateTimeEditor = TryCast(e.ActiveEditor, RadDateTimeEditor)
If editor IsNot Nothing Then
Dim el As RadDateTimeEditorElement = TryCast(editor.EditorElement, RadDateTimeEditorElement)
el.Format = DateTimePickerFormat.Custom
el.CustomFormat = "dd/MM/yyyy hh:mm"
el.ShowTimePicker = True
el.CalendarSize = New Size(400, 300)
el.Calendar.ShowFooter = True
Dim calendarBehavior As RadDateTimePickerCalendar = TryCast(el.GetCurrentBehavior(), RadDateTimePickerCalendar)
RemoveHandler calendarBehavior.TimePicker.CloseButtonClicked, AddressOf TimePicker_CloseButtonClicked
AddHandler calendarBehavior.TimePicker.CloseButtonClicked, AddressOf TimePicker_CloseButtonClicked
End If
End Sub
Private Sub TimePicker_CloseButtonClicked(sender As Object, e As EventArgs)
Console.WriteLine("Close")
End Sub
Should you have further questions please let me know.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik