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

DateTimePicker Pick Both Date and Time - Winform

8 Answers 2810 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Tim
Top achievements
Rank 1
Tim asked on 12 Feb 2020, 07:57 PM

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

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Feb 2020, 08:00 AM

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

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
Tim
Top achievements
Rank 1
answered on 17 Feb 2020, 06:40 PM

Thanks for the info, it worked.

Is it possible to do the same with a GridViewDateTimeColumn?

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Feb 2020, 09:05 AM
Hello, Tim,

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);
            }
        }
Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
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
Tim
Top achievements
Rank 1
answered on 20 Feb 2020, 01:17 PM

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.

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Feb 2020, 02:35 PM
Hello, Tim,

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)
        {
        }
I hope this information helps.  

Regards,
Dess | Tech Support Engineer, Sr.
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
Tim
Top achievements
Rank 1
answered on 24 Feb 2020, 05:51 PM

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

0
Tim
Top achievements
Rank 1
answered on 24 Feb 2020, 06:04 PM

Never mind, it wasn't in the intellisense but it works.

Thanks!!!

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Feb 2020, 12:49 PM

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
I have also attached a sample VB project for your reference. 

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
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.
Tags
DateTimePicker
Asked by
Tim
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Tim
Top achievements
Rank 1
Share this question
or