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

Input format different to display format?

7 Answers 191 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Gert
Top achievements
Rank 1
Gert asked on 31 Jan 2020, 12:28 PM

Hi, 

 

is it possible to enter 030120 but have the Preview ToolTip in format dd.MM.yyyy and also wenn leaving the control (d1.jpg, d2.jpg, d3.jpg, d4.jpg)?

 

BR Gert

7 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 04 Feb 2020, 01:59 PM

Hi Gert,

Thank you for the provided images.

One idea that comes to mind is to set both the Short and Long date and time patterns of the picker's Culture and set the DisplayFormat property to use the Long format. As the RadDateTimePicker will use the Short patterns for the input, this should provide the desired result.

Here's what I have in mind:

            this.radDateTimePicker.Culture = new System.Globalization.CultureInfo("en-US");
            this.radDateTimePicker.Culture.DateTimeFormat.ShortDatePattern = "ddMMyy";
            this.radDateTimePicker.Culture.DateTimeFormat.ShortTimePattern = "HHmm";
            this.radDateTimePicker.Culture.DateTimeFormat.LongDatePattern = "dd.MM.yyyy";
            this.radDateTimePicker.Culture.DateTimeFormat.LongTimePattern = "";
<telerik:RadDateTimePicker x:Name="radDateTimePicker" DisplayFormat="Long" />
I've also prepared a small sample project to demonstrate this in action. Please find it attached to my reply.

Could you please have and let me know if such an approach would work for you? I will be awaiting your reply.

Regards,
Dilyan Traykov
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
Gert
Top achievements
Rank 1
answered on 06 Feb 2020, 08:27 AM

Hi Dilyan,

this is working perfect for me for RadDatePicker as a stand alone control, but how can I achive the same behavior in my derived GridViewDateColumn? In this case I do not need the Preview Tooltip. (girdDate1.jpg)

 

    public class FWDateColumn : GridViewDataColumn
    {

        public FWDateColumn()
        {
            Style editorStyle = new Style(typeof(RadDatePicker));
            Setter setter = new Setter(DataGridRow.PaddingProperty, new Thickness(0));
            editorStyle.Setters.Add(setter);
            Setter setter2 = new Setter(DataGridRow.VerticalAlignmentProperty, VerticalAlignment.Center);
            editorStyle.Setters.Add(setter2);
            editorStyle.BasedOn = (Style)FindResource(typeof(RadDatePicker));
            EditorStyle = editorStyle;
        }

...

}

 

Thank you very much for your great support.

BR Gert

0
Accepted
Dilyan Traykov
Telerik team
answered on 07 Feb 2020, 05:05 PM

Hi Gert,

To achieve this in the context of the RadGridView control, you can override the CreateCellEditElement method like so:

    public class FWDateColumn : GridViewDataColumn
    {
        // ...

        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            var editor = base.CreateCellEditElement(cell, dataItem) as RadDateTimePicker;
            
            editor.Culture = new System.Globalization.CultureInfo("en-US");
            editor.Culture.DateTimeFormat.ShortDatePattern = "ddMMyy";
            editor.Culture.DateTimeFormat.ShortTimePattern = "HHmm";
            editor.Culture.DateTimeFormat.LongDatePattern = "dd.MM.yyyy";
            editor.Culture.DateTimeFormat.LongTimePattern = "";
            editor.DisplayFormat = DateTimePickerFormat.Long;

            return editor;
        }
    }
Alternatively, you can handle the PreparedCellForEdit event of the RadGridView control:

        private void GridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e)
        {
            var editor = e.EditingElement as RadDateTimePicker;
            if (editor != null)
            {
                editor.Culture = new System.Globalization.CultureInfo("en-US");
                editor.Culture.DateTimeFormat.ShortDatePattern = "ddMMyy";
                editor.Culture.DateTimeFormat.ShortTimePattern = "HHmm";
                editor.Culture.DateTimeFormat.LongDatePattern = "dd.MM.yyyy";
                editor.Culture.DateTimeFormat.LongTimePattern = "";
                editor.DisplayFormat = DateTimePickerFormat.Long;
            }
        }

Please let me know if any of these approaches works for you.

Regards,
Dilyan Traykov
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
Gert
Top achievements
Rank 1
answered on 13 Feb 2020, 06:44 AM

Hi Dilyan,

 

this is working perfekt!!!!! 

 

Thanks a lot, BR
Gert

0
Gert
Top achievements
Rank 1
answered on 21 Feb 2020, 08:06 AM

After a few days working in production with this new format behaviors some of the users (ofcause) are complaining that they are not able now to copy - paste dates (e.g. 21.02.2020) from one date column to the other.

Just out of curiosity, is it possible some how to switch the ShortDatePattern depenting on the input string or in other words when the user is entering a "."  or the paste string contains any "." the ShortDatePattern switches to "dd.MM.yyyy" else it is "ddMMyy" ??

 

This would be the superlative solution for our system.

Thanks in advance,
Gert

 

 

0
Accepted
Dilyan Traykov
Telerik team
answered on 21 Feb 2020, 04:54 PM

Hi Gert,

In such case, I can suggest creating custom parsing logic for the control as explained in this article. Alternatively, you can handle the PastingCellClipboardContent event of the RadGridView control.

Please let me know if any of these approaches would work for you.

Regards,
Dilyan Traykov
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
Gert
Top achievements
Rank 1
answered on 26 Feb 2020, 09:52 AM

Hi Dilyan,

the ParseDateTimeValue event meets exact all my needs. Thanks a lot!!!
In the future I have to spend more time in telerik documentation, I promise.

Have a nice day!!
BR Gert

Tags
DateTimePicker
Asked by
Gert
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Gert
Top achievements
Rank 1
Share this question
or