New to Telerik UI for WinForms? Start a free 30-day trial
Implementing a Custom Freeform Date Parser in RadDateTimePicker
Updated on Jan 8, 2026
Environment
| Product Version | Product | Author |
|---|---|---|
| 2025.4.1111 | RadDateTimePicker for WinForms | Dinko Krastev |
Description
In this article we will demonstrate how to enhance the functionality of the RadDateTimePicker by allowing users to input custom freeform text, such as "today - 4w" or "bomonth - 6m". The goal is to run a custom parser first, which processes the input according to specific rules. If the custom parser fails, the input should fall back to the standard parser.
Solution
To achieve the desired functionality, create a custom class that inherits from the FreeFormDateTimeProvider class. Override the OnParsingDateTime method to implement custom parsing logic. If your parser successfully parses the input, return the parsed result; otherwise, call the base method to fall back to the default parser.
- Set the
MaskTypeproperty of the RadDateTimePicker toFreeFormDateTime. - Assign your custom provider to the
TextBoxElement.Providerproperty. - Implement your parsing logic in the overridden
OnParsingDateTimemethod.
Example code:
C#
// Configure RadDateTimePicker to use FreeFormDateTimeProvider
radDateTimePicker1.DateTimePickerElement.TextBoxElement.MaskType = MaskType.FreeFormDateTime;
radDateTimePicker1.DateTimePickerElement.TextBoxElement.Provider = new MyFreeFormProvider(provider.Mask, provider.Culture, provider.Owner);
// Custom FreeFormDateTimeProvider class
public class MyFreeFormProvider : FreeFormDateTimeProvider
{
public MyFreeFormProvider(string mask, CultureInfo culture, RadMaskedEditBoxElement owner) : base(mask, culture, owner)
{
}
public override void OnParsingDateTime(ParsingDateTimeEventArgs e)
{
var inputString = e.InputString;
// Custom parsing logic
bool success = DateTime.TryParse(inputString, out DateTime parsedDate);
if (success)
{
e.Result = parsedDate;
return; // Exit if successfully parsed
}
// Fallback to base parser
base.OnParsingDateTime(e);
}
}