This project has moved. For the latest updates, please go here.

DateTimePicker and DateTimeUpDown with a Custom Format can cause a System.InvalidOperationException: Sequence contains no elements

Sep 12, 2014 at 4:24 PM
Edited Sep 12, 2014 at 5:44 PM
Hello,
A System.InvalidOperationException can occurs in a DateTimePicker and a DateTimeUpDown control if the Format is set to « Custom ». Actually, the two controls cause the same error because DateTimePicker inherits from DateTimeUpDown for the Format property.

How to reproduce :
  1. Implements a DateTimePicker (or DateTimeUpDown) with a Custom Format.
  2. In the UI, enter one of the following character as the first character (dot, comma, colon, semi-colon, slash … among others)
  3. A System.InvalidOperationException: Sequence contains no elements will occurs.
You can see the complete message with details below :

Message: System.InvalidOperationException: La séquence ne contient aucun élément.
à System.Linq.Enumerable.Last[TSource](IEnumerable1 source)
à Xceed.Wpf.Toolkit.Core.Primitives.DateTimeUpDownBase
1.GetPreviousDateTimeInfo(Int32 previousSelectionStart)
à Xceed.Wpf.Toolkit.Core.Primitives.DateTimeUpDownBase1.PerformKeyboardSelection(Int32 nextSelectionStart)
à Xceed.Wpf.Toolkit.Core.Primitives.DateTimeUpDownBase
1.OnPreviewKeyDown(KeyEventArgs e)
à Xceed.Wpf.Toolkit.DateTimePicker.OnPreviewKeyDown(KeyEventArgs e)
à System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
à System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
à System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
à System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
à System.Windows.Input.InputManager.ProcessStagingArea()
à System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
à System.Windows.Interop.HwndKeyboardInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawKeyboardActions actions, Int32 scanCode, Boolean isExtendedKey, Boolean isSystemKey, Int32 virtualKey)
à System.Windows.Interop.HwndKeyboardInputProvider.ProcessKeyAction(MSG& msg, Boolean& handled)
à System.Windows.Interop.HwndSource.CriticalTranslateAccelerator(MSG& msg, ModifierKeys modifiers)
à System.Windows.Interop.HwndSource.OnPreprocessMessage(Object param)
à System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
à MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
Developer
Sep 12, 2014 at 7:18 PM