Unplanned
Last Updated: 21 Mar 2023 09:12 by ADMIN
Martin
Created on: 15 Mar 2023 15:03
Category: UI for WinForms
Type: Bug Report
0
RadVirtualGrid DateTime dropdown causes NullReferenceException

Repro steps:

  1. Create a RadVirtualGrid with:
    1. A column with a nullable DateTime
    2. Another column with a string or number.
  2. Fill it with one or more rows. The DateTimes remain null.
  3. Edit a DateTime cell, open the dropdown:

  4. Click op button [Today], the date/time in the cell changes.
  5. Click [Tab], the focuses moves to the next cell, but the dropdown remains open:
  6. Click somewhere else in the grid or form, an Exception is thrown:
System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.WinControls.UI.RadDateTimePickerCalendar.popupControl_Closing(Object sender, RadPopupClosingEventArgs args)

Expected behavior:

  • The dropdown closes after moving to another cell.
  • No exception occurs.

 

 

1 comment
ADMIN
Dinko | Tech Support Engineer
Posted on: 21 Mar 2023 09:12

Hi Martin,

The provided steps are greatly appreciated. By following them I was able to reproduce this exception and I can confirm that this is unexpected and the drop-down part should be closed when moving to another cell. The exception itself comes from the fact that the RadDateTimePicker element is no longer visible when another cell is in edit mode.

What I can suggest as a workaround is to create a custom InputBehavior and override the HandleTabKey() method. In the method, you could get the current VirtualGridDateTimeEditor from the ActiveEditor property of the RadVirtualGrid. Then you can manually close the Popup part.

public class CustomVirtualGridInputBehavior : VirtualGridInputBehavior
{
    public CustomVirtualGridInputBehavior(RadVirtualGridElement gridElement) : base(gridElement)
    {
    }
    protected override bool HandleTabKey(KeyEventArgs keys)
    {
        var editor = this.GridElement.ActiveEditor;
        if(editor != null)
        {
            var dateTimeEditor = editor as VirtualGridDateTimeEditor;
            if (dateTimeEditor != null)
            {

                var editorElement = dateTimeEditor.EditorElement as RadDateTimeEditorElement;
                (editorElement.CurrentBehavior as RadDateTimePickerCalendar).PopupControl.ClosePopup(new PopupCloseInfo(RadPopupCloseReason.ParentClosed, ""));
            }
        }
            
        return base.HandleTabKey(keys);
    }
}

this.radVirtualGrid1.VirtualGridElement.InputBehavior = new CustomVirtualGridInputBehavior(this.radVirtualGrid1.VirtualGridElement);

Your Telerik Points are updated for your time reporting this exception.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.