Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Date formatting
posted

Hello, How to set the grid cell level date format and input mask for dd-MMM-yy (25-May-23) format ? I tried with date editor component but nothing working. Please assist. Thanks

Parents
No Data
Reply
  • 1700
    Offline posted

    Hello Shawn,

    You can apply format for the column with the following code:

     this.ultraGrid1.DisplayLayout.Bands[0].Columns["Date"].Format = "dd-MMM-yy";

    This would apply the correct format out of edit mode, the reason why you are not able to add MaskInput is that “MMM” is text and by design DateTimeColumns are handled with UltraDateTimeEditor, which only handles numbers in its edit mode. Once the user enters edit mode a calendar would appear and the date 29-May-2023 would appear as 29-05-2023, which the user would be able to edit through the keyboard and the calendar.

    Another alternative would be to use UltraCalendar combo as EditorComponent for the column. By doing this you would be able set the correct format - "dd-MMM-yy" for both in and out of edit mode. It could be done with the following code:

     

                UltraCalendarCombo calendarCombo = new UltraCalendarCombo();
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["Date"].EditorComponent = calendarCombo;            
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["Date"].Format = "dd-MMM-yy";
                this.ultraGrid1.DisplayLayout.Bands[0].Columns["Date"].MaskInput = "dd-MMM-yy";

    Please try both approaches and let me know if you have any questions.

    Regards,
    Ivan Kitanov

Children