Input format different to display format?

8 posts, 2 answers
  1. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 31 Jan 2020 Link to this post

    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

  2. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1258 posts

    Posted 04 Feb 2020 Link to this post

    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.
  3. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 06 Feb 2020 in reply to Dilyan Traykov Link to this post

    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

  4. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1258 posts

    Posted 07 Feb 2020 Link to this post

    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.
  5. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 13 Feb 2020 in reply to Dilyan Traykov Link to this post

    Hi Dilyan,

     

    this is working perfekt!!!!! 

     

    Thanks a lot, BR
    Gert

  6. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 21 Feb 2020 Link to this post

    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

     

     

  7. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    1258 posts

    Posted 21 Feb 2020 Link to this post

    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.
  8. Gert
    Gert avatar
    35 posts
    Member since:
    Nov 2017

    Posted 26 Feb 2020 in reply to Dilyan Traykov Link to this post

    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

Back to Top