Current filter:
                                You should refresh the page.
                                  • I have a number of DateEdit and TimeEdit controls on my form. I use a custom formatter to show DateTime.MinValue as blank on a DateEdit control

                                    [C#]
                                    DeadlineDateEdit.Properties.DisplayFormat.Format = new DefaultDateFormatter(); /// <summary> /// A custom formatter which displays the default date of 01/01/0001 as blank /// </summary> class DefaultDateFormatter : IFormatProvider, ICustomFormatter { public string Format(string format, object arg, IFormatProvider formatProvider) { string formatValue = arg.ToString(); DateTime dateTime; DateTime.TryParse(formatValue, out dateTime); return (dateTime == DateTime.MinValue) ? "" : dateTime.ToString("ddd dd MMM", formatProvider); } public object GetFormat(Type formatType) { return this; } }

                                    This works fine for date. But when I try something similar for time I still see "00:00" not blank:

                                    [C#]
                                    DeadlineTimeEdit.Properties.DisplayFormat.Format = new DefaultTimeFormatter(); /// <summary> /// A custom formatter which displays the deadline time in a 24 hour format /// </summary> class DefaultTimeFormatter : IFormatProvider, ICustomFormatter { public string Format(string format, object arg, IFormatProvider formatProvider) { string formatValue = arg.ToString(); DateTime dateTime; DateTime.TryParse(formatValue, out dateTime); return (dateTime == DateTime.MinValue) ? "" : dateTime.ToString("HH:mm", formatProvider); } public object GetFormat(Type formatType) { return this; } }

                                    Any suggestions for why dates are being blanked successfully but not times? It does show times in HH:mm rather than HH:mm:ss format so I can tell the code is working, but it won't show blank instead of 00:00.

                                • Aleks (DevExpress Support) 08.23.2019

                                  Hello,

                                  Thank you for your code snippets. They both look correct to me. I checked them in a small sample and found that the Format method of DefaultTimeFormatter is not called until any non-default value is assigned to DeadlineTimeEdit.Properties.DisplayFormat.FormatString. I now need more time to investigate this. Please bear with me.

                                1 Solution

                                Creation Date Importance Sort by

                                Thank you for your patience. I finished my investigation. When you use TimeEdit, it is supposed that you format data based on a certain format string. That is why the Format method is called only when there is a value in FormatString. So, to format your values as you require, simply assign any string to DeadlineTimeEdit.Properties.DisplayFormat.FormatString. Let me know if you have additional questions.

                                • Spa2004 08.28.2019

                                  That's fixed it. I set the FormatString to HH:mm and it is now working properly and calling the CustomFormatter. Thanks for your help.

                                • Aleks (DevExpress Support) 08.28.2019

                                  You are welcome. Do not hesitate to contact us if you have any other questions or concerns. We are here to help you.