Date Picker Custom Date Format

Posted by: msloan on 28 March 2018, 10:44 pm EST

    • Post Options:
    • Link

    Posted 28 March 2018, 10:44 pm EST

    I am trying to set up the Filter on a Date/Time column of a Data Grid to be Date Only, with a custom Date Format:

    
    // Set Format for Date Filter
    ((C1.WPF.DataGrid.DataGridDateTimeColumn)L_objColumn).EditMode = C1.WPF.DataGrid.DataGridDateTimeColumnEditMode.Date;
    ((C1.WPF.DataGrid.DataGridDateTimeColumn)L_objColumn).DateFormat = C1.WPF.DateTimeEditors.C1DatePickerFormat.Custom;
    ((C1.WPF.DataGrid.DataGridDateTimeColumn)L_objColumn).CustomDateFormat = "dd/MM/yyyy";
    
    

    Only the Date Picker is displayed but when I pick a date, it is displayed in the Filter as Date + ’ 00:00:00’. Is there any way to stop this happening?

  • Posted 1 April 2018, 5:36 pm EST

    Hello,

    Skipping setting the DateFormat and directly setting the CustomDateFormat, we were able to get the desired output. Please verify the behavior as shown in below video.



    Also, attached is sample application for your reference.

    Regards,

    Ruchir AgarwalCustom_C1DatetimePicker.zip

  • Posted 3 April 2018, 8:09 pm EST

    Hi,

    I can confirm that both in your sample project and mine (with the suggested change) the Date Filter no longer displays the ‘00:00:00’. However the date format for the filter is ‘M/d/yyyy’ NOT the Date format of the Date column (‘dd/MM/yyyy’).

    Is there any way to fix this?

    Thanks for your assistance,

    Mark Sloan

  • Posted 4 April 2018, 11:22 pm EST

    Hi Mark,

    I could observe what you pointed at.

    We are working to see if there is any way to achieve the requirement. And, we’ll get back to you soon.

    Regards,

    Ruchir Agarwal

  • Posted 10 April 2018, 11:09 pm EST

    Hello Mark,

    We are not sure whether there can be a good fix to this issue that works for all the culture with arbitrary format.

    What we understand is if you are needing such date format, probably you are preferring some culture different from US one. In which case, we suggest you to use Short date format like this: ```

    (_flex.Columns[“Hired”] as C1.WPF.DataGrid.DataGridDateTimeColumn).EditMode = C1.WPF.DataGrid.DataGridDateTimeColumnEditMode.Date;

    (_flex.Columns[“Hired”] as C1.WPF.DataGrid.DataGridDateTimeColumn).DateFormat = C1.WPF.DateTimeEditors.C1DatePickerFormat.Short;

    Along with this, you also need to make the application culture-aware, since our controls honor [b]FrameworkElement.Language[/b] property, for this you need to set [b]Language[/b] property according to [b]CurrentCulture[/b] settings used in application (by default it is current culture set by OS). OR if you wish to set some specific culture in your application, you should set both [b]Language[/b] and thread culture like this:```
                // set thread culture
    System.Threading.Thread.CurrentThread.CurrentCulture = System.Threading.Thread.CurrentThread.CurrentUICulture =
    new System.Globalization.CultureInfo("en-GB");
                // set language according to the current culture used in OS
    this.Language = System.Windows.Markup.XmlLanguage.GetLanguage(System.Threading.Thread.CurrentThread.CurrentCulture.Name);
    
    

    Using above code, we get ‘dd.MM.yyyy’ format in Russian culture, “dd-MM-yyyy” in Danish and “dd/MM/yyyy” for UK etc

    Hope this helps.

    Regards,

    Ruchir Agarwal

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels