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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridModelSelections.GetSelectedRows(true, false) throwing NullReferenceException

Thread ID:

Created:

Updated:

Platform:

Replies:

128708 Feb 7,2017 09:23 AM UTC Feb 14,2017 12:34 PM UTC Windows Forms 3
loading
Tags: GridControl
Angus Tang
Asked On February 7, 2017 09:23 AM UTC

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!


Piruthiviraj Malaimelraj [Syncfusion]
Replied On 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

Angus Tang
Replied On 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


Piruthiviraj Malaimelraj [Syncfusion]
Replied On 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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;