We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

GridModelSelections.GetSelectedRows(true, false) throwing NullReferenceException

I am using Syncfusion v7.3 and I got System.NullReferenceException in the following code:
foreach (GridRangeInfo ri in this.Selections.GetSelectedRows(true, false)) // throw exception in this.Selections.GetSelectedRows(true, false)
    for (int i = ri.Top; i <= ri.Bottom; i++)
    {
        int rowIdx = i - 1;
        ...
     }

Relevant stacktrace:

Object reference not set to an instance of an object.
Syncfusion.Grid.Windows
Data : System.Collections.ListDictionaryInternal
TargetSite : Void RemoveEmptyRanges()
HResult : -2147467261
  at Syncfusion.Windows.Forms.Grid.GridRangeInfoList.RemoveEmptyRanges()
   at Syncfusion.Windows.Forms.Grid.GridRangeInfoList.GetRowRanges(GridRangeInfoType filter)
   at Syncfusion.Windows.Forms.Grid.GridModelSelections.GetSelectedRows(Boolean bRangeRowsOnly, Boolean considerCurrentCell)

Strange enough, when watching the variables in Visual Studio, I find the following:

this.Selections {Syncfusion.Windows.Forms.Grid.GridModelSelections}
  - Count = 2
  - Results View
    - [0] = {30325}
    - [1] = null

On and off the corresponding data grid becomes a big red cross with white background after this exception is thrown.

Can I know why it happens? Is it fixed in some newer version of Syncfusion? Or anything I need to pay attention when calling this method?

Thanks!


3 Replies

PM Piruthiviraj Malaimelraj Syncfusion Team February 8, 2017 07:03 AM UTC

Hi Angus, 

Thanks for using Syncfusion products. 

We have analyzed this reported scenario and created the simple sample as per your scenario. We have tried to reproduce the reported scenario with different selection kinds(ListBoxSelectionMode or AllowSelection) by possible ways but unfortunately we could not able to reproduce the issue. Could you please provide the following details of your scenario, 

·         Please confirm us whether you have used CustomControl in your sample project because your code seems like that you are using CustomControl in your application. 
·         Please let us know which selection(ListBoxSelectionMode or AllowSelection) kind has been used in your sample. 
·         Please provide us with simple video of your sample execution which represents the replication procedure of the scenario or if possible, modify the attached sample with issue reproducible. 
·         Please ensure whether the reported exception has reproduced in attached sample. 

Sample link: 

Note: 
The selected range can be retrieved by using Selections.Ranges collection also. Please make use of the below code, 

this.gridControl1.ListBoxSelectionMode = SelectionMode.MultiSimple; 
//this.gridControl1.AllowSelection = GridSelectionFlags.Any; 

private void button1_Click(object sender, EventArgs e) 
    foreach (GridRangeInfo ri in this.gridControl1.Selections.Ranges
    { 
        for (int i = ri.Top; i <= ri.Bottom; i++) 
        { 
            int rowIdx = i - 1; 
            //your code. 
        } 
    } 
 
Regards, 
Piruthiviraj


AT Angus Tang February 13, 2017 03:41 AM UTC

Hi Piruthiviraj, 

We are using a custom class DataGrid : Syncfusion.Windows.Forms.Grid.GridControl, with ListBoxSelectionMode = SelectionMode.MultiExtended. We use a custom cell model.

However I cannot always reproduce the issue. It sometimes happen when I sort the column or filter the data of data grid. We have a refresh timer to update the data grid from datasource when needed as well.

Can I know does Selections.Ranges return the same output as Selections.GetSelectedRows(true, false)? As from my memory dump the former seems working fine while latter throwing the exception, and it may solve my issue.

Many thanks, 
Angus



PM Piruthiviraj Malaimelraj Syncfusion Team February 14, 2017 12:34 PM UTC

Hi Angus, 

Thanks for the update. 

Query 
Response 
 
However I cannot always reproduce the issue. It sometimes happen when I sort the column or filter the data of data grid. We have a refresh timer to update the data grid from datasource when needed as well. 
We have created the sample as per your scenario (i.e create the custom control from GridControl) and updated the data source for particular time interval.  Unfortunately we could not able to reproduce the issue. Please refer to the attached sample and let us know if we missed anything from your customization. 

Sample link: 
 
 
Can I know does Selections.Ranges return the same output as Selections.GetSelectedRows(true, false)?  
Yes. The Selections.Ranges and Selections.GetSelectedRows() methods will returns the same output. 

Please refer to the below KB for further references, 


Regards, 
Piruthiviraj

Loader.
Live Chat Icon For mobile
Up arrow icon