NullReferenceException clicking on RadGridView empty area

7 posts, 0 answers
  1. Stefano
    Stefano avatar
    11 posts
    Member since:
    Feb 2012

    Posted 06 Dec 2018 Link to this post

    Grid just populated with few rows, so there is an empty area below those rows.

    Multiselection is enabled.

    Grid has just been populated, so there are no selected rows.

    If I click on the empty area below the rows, I get this exception:

    System.Exception: Exception caught by
    CurrentDomain.UnhandledException - type: System.NullReferenceException value:
    System.NullReferenceException: Object reference not set to an instance of an
    object.<br>   at
    Telerik.WinControls.UI.GridRowBehavior.DoMultiFullRowSelect(GridCellElement
    currentCell, Point currentLocation)<br>   at
    Telerik.WinControls.UI.GridRowBehavior.DoMouseSelection(GridCellElement
    currentCell, Point currentLocation)<br>   at
    Telerik.WinControls.UI.GridRowBehavior.ProcessMouseSelection(Point
    mousePosition, GridCellElement currentCell)<br>   at
    Telerik.WinControls.UI.GridRowBehavior.OnMouseMove(MouseEventArgs e)<br>   at
    Telerik.WinControls.UI.BaseGridBehavior.OnMouseMove(MouseEventArgs e)<br>   at
    Telerik.WinControls.UI.RadGridView.OnMouseMove(MouseEventArgs e)<br>   at
    System.Windows.Forms.Control.WmMouseMove(Message& m)<br>   at
    System.Windows.Forms.Control.WndProc(Message& m)<br>   at
    Telerik.WinControls.RadControl.WndProc(Message& m)

     

    if I select a row, before clicking on the empty area, nothing happens.

    I could preselect a row, just after populating. but I'd like to understand why this happens

     

  2. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 06 Dec 2018 Link to this post

    Hi Stefano,

    I was not able to reproduce the observed behavior on my end. For convenience, I prepared a small sample, based on the information that you provided so far and attached it to this thread. Could you please check it and let me know how it differs from your real setup? 

    Could you please confirm that you are using the latest version of the suite as well.

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Stefano
    Stefano avatar
    11 posts
    Member since:
    Feb 2012

    Posted 07 Dec 2018 in reply to Dimitar Link to this post

    thanks dimitar

    Your sample works. I've modified it so now it crashes, and in the process, I've tracked it down to theme being the problem. in other words:

    - without no themes applied, no errors

    - with VisualStudio2012Light theme applied, it crashes

    No, I'm not on the latest. I'm using 2015_2_728

    Apparently I

  4. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 10 Dec 2018 Link to this post

    Hi Stefano,

    I was able to reproduce the issue with the specified version. This is an old issue and it is fixed in R1 2016. 

    To work around it with the version that you are using you need a custom row behavior. Here is the code:
    class MyGridDataRowBehavior : GridDataRowBehavior
    {
        protected override bool ProcessMouseSelection(Point mousePosition, GridCellElement currentCell)
        {
            var prop = typeof(GridRowBehavior).GetField("orderedRows", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(this);
      
            if (prop == null)
            {
                return false;
            }
            return base.ProcessMouseSelection(mousePosition, currentCell);
        }
    }

    Register the above behavior with the following code:
    BaseGridBehavior gridBehavior = radGridView1.GridBehavior as BaseGridBehavior;
    gridBehavior.UnregisterBehavior(typeof(GridViewDataRowInfo));
    gridBehavior.RegisterBehavior(typeof(GridViewDataRowInfo), new MyGridDataRowBehavior());

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Stefano
    Stefano avatar
    11 posts
    Member since:
    Feb 2012

    Posted 12 Dec 2018 in reply to Dimitar Link to this post

    thanks Dimitar

    unfortunately the issue is not fixed. it happens less often, but still happens. i've also tryed this, but still not solves

    protected override bool ProcessMouseSelection(Point mousePosition, GridCellElement currentCell)
    {
        var prop = typeof(GridRowBehavior).GetField("orderedRows", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(this);
     
        if (prop == null)
        {
            Console.WriteLine("MyGridDataRowBehavior prop was null");
            return false;
        }
     
        var currentCellValue = currentCell == null ? "null" : (currentCell.Value == null ? ".Value is null" : currentCell.Value.ToString());
        Console.WriteLine($"base.ProcessMouseSelection mousePosition={mousePosition.ToString()} currentCell:{currentCellValue}");
     
        try
        {
            return base.ProcessMouseSelection(mousePosition, currentCell);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            return false;
        }
    }

     

  6. Stefano
    Stefano avatar
    11 posts
    Member since:
    Feb 2012

    Posted 12 Dec 2018 Link to this post

    when it crashes, 'prop', 'mousePosition' and 'currentCell' are all valid

  7. Dimitar
    Admin
    Dimitar avatar
    2949 posts

    Posted 13 Dec 2018 Link to this post

    Hi Stefano,

    I have attached an updated version of the test project. Could you please try it and let me know if you still can reproduce the issue (I tried many times but there is no exception on my side). 

    If the objects are valid maybe this is another exception. Could you check if the StackTrace is the same? 

    I am looking forward to your reply.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top