Input Mask für ein UltraCalendarCombo
Leider besitzt das UltraCalendarCombo standardmäßig keine Input Mask, man muss sich daher anders helfen.
Ziel war es eine Datumseingabe im Format TTMMJJJJ zu ermöglichen.
Im Infragistics Forum habe ich diesen Beitrag gefunden und noch etwas umgestaltet, jetzt funktionieren folgende Eingabe-Formate:
TTMMJJJJ
TTMMJJ
TT.MM.JJJJ
TT.MM.JJ
eine Erweiterung auf TMJJ wäre auch noch möglich...
private static void OnUltraCalendarCombo_ValidationError(object sender, DateValidationErrorEventArgs e) { var control = sender as UltraCalendarCombo; if (control == null) return; if (e.ErrorCode != DateValidationError.UnableToParseValue) goto exitWithError; // Get the embeddable element that handles the text editing var controlElement = control.UIElement; if (controlElement == null) return; var editor = controlElement.GetDescendant(typeof(EditorWithTextUIElement)) as EditorWithTextUIElement; if (editor == null) return; // Get the text as typed by the user var rawValue = editor.Editor.CurrentEditText; // This conditional can be loosened to allow other parsing scenarios. // Note that this implementation only supports // MM/dd/yy, MM/dd/yyyy, dd/MM/yy, and dd/MM/yyyy. if (rawValue.Length != 6 && rawValue.Length != 8) goto exitWithError; // Assume the text length of the year component to be either 2 or 4, // based on the total input string length. var yearLen = rawValue.Length == 6 ? 2 : 4; var dateSeparator = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DateSeparator; // Build a string from the input digits that can be parsed into a date var dateString = string.Format("{1}{0}{2}{0}{3}", dateSeparator, rawValue.Substring(0, 2), rawValue.Substring(2, 2), rawValue.Substring(4, yearLen)); // Try to parse the string into a date DateTime value; if (DateTime.TryParse(dateString, out value)) { e.NewValue = value; return; } exitWithError: ieg.Gui.Messages.Error.Show("Bitte geben sie ein passendes Datum im Format TTMMJJJJ oder TT.MM.JJJJ ein!"); }


