Unplanned
Last Updated: 17 Apr 2024 14:45 by ADMIN
Al
Created on: 27 Apr 2022 07:28
Category: TimePicker
Type: Bug Report
2
RadTimePicker: NullReferenceException when setting Value to null in the ValueChanged event

Run the attached project and select a new value from the drop down for RadTimePicker:

 

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.RadTimePickerElement.set_Value(Object value) in C:\Work\Development\RadControls\RadControlsUI\RadTimePicker\Elements\RadTimePickerElement.cs:line 594
   at Telerik.WinControls.UI.RadTimePickerContentElement.element_Click(Object sender, EventArgs e) in C:\Work\Development\RadControls\RadControlsUI\RadTimePicker\Elements\ContentPart\RadTimePickerContentElement.cs:line 585
   at Telerik.WinControls.RadElement.OnClick(EventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 5094
   at Telerik.WinControls.RadElement.DoClick(EventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 5158
   at Telerik.WinControls.RadElement.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 4272
   at Telerik.WinControls.RadItem.RaiseBubbleEvent(RadElement sender, RoutedEventArgs args) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadItem.cs:line 779
   at Telerik.WinControls.RadElement.RaiseRoutedEvent(RadElement sender, RoutedEventArgs args) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 4179
   at Telerik.WinControls.RadElement.DoMouseUp(MouseEventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 5271
   at Telerik.WinControls.RadElement.CallDoMouseUp(MouseEventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Element\RadElement.cs:line 5493
   at Telerik.WinControls.ComponentInputBehavior.OnMouseUp(MouseEventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Control\ComponentInputBehavior.cs:line 75
   at Telerik.WinControls.RadControl.OnMouseUp(MouseEventArgs e) in C:\Work\Development\RadControls\RadControl\TPF\Control\RadControl.cs:line 1206
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m) in C:\Work\Development\RadControls\RadControl\TPF\Control\RadControl.cs:line 1554
   at Telerik.WinControls.UI.RadPopupControlBase.WndProc(Message& m) in C:\Work\Development\RadControls\RadControlsUI\GenericPopup\RadPopupControlBase.cs:line 795
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Workaround:

        Timer t = new Timer();

        private void RadTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            if (radTimePicker1.Value == null) return;

            var timeval = ((DateTime)radTimePicker1.Value).TimeOfDay;

            if (timeval == TimeSpan.Zero)
            {
                t = new Timer();
                t.Interval = 500;
                t.Tick += T_Tick; t.Start();
            }
        }

        private void T_Tick(object sender, EventArgs e)
        {
            t.Stop();
            this.radTimePicker1.ValueChanged -= RadTimePicker1_ValueChanged;
            this.radTimePicker1.Value = null;
            this.radTimePicker1.ValueChanged += RadTimePicker1_ValueChanged;
        }

0 comments