This is a migrated thread and some comments may be shown as answers.

NullReferenceException clicking on RadGridView empty area

6 Answers 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stefano
Top achievements
Rank 1
Stefano asked on 06 Dec 2018, 09:20 AM

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

 

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 06 Dec 2018, 11:26 AM
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.
0
Stefano
Top achievements
Rank 1
answered on 07 Dec 2018, 02:48 PM

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

0
Dimitar
Telerik team
answered on 10 Dec 2018, 10:50 AM
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.
0
Stefano
Top achievements
Rank 1
answered on 12 Dec 2018, 12:09 PM

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;
    }
}

 

0
Stefano
Top achievements
Rank 1
answered on 12 Dec 2018, 12:18 PM

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

0
Dimitar
Telerik team
answered on 13 Dec 2018, 09:32 AM
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.
Tags
General Discussions
Asked by
Stefano
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Stefano
Top achievements
Rank 1
Share this question
or