SfDataGrid exception when the collection changes during a Sort operation

I am using C#.

My grid sorts itself frequently based on the underlying data, which changes often. This is great. However, when the ObservableCollection size is modified (by adding or removing an object) while the sorting is taking place, I get a fatal error: "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"

Naturally, I expect any iteration to break when its collection is changed mid-loop. But I need to prevent this occurrence from crashing my app. Please help me understand why this exception is not being caught by the following code:


ExceptionManager.ExceptionCatched += ExceptionManager_ExceptionCatched; // Per Syncfusion's recommendation, I wire this handler before initializing the component to be sure it catches all possible exceptions.

InitializeComponent();


private void ExceptionManager_ExceptionCatched(object sender, ExceptionCatchedEventArgs e)

{

// log the exception here and keep going

}



Ideally when a Sort operation breaks, the app would just refresh the view and continue functioning normally. How can I achieve this?

Thank you!


1 Reply

BT Balamurugan Thirumalaikumar Syncfusion Team September 6, 2021 07:06 PM UTC

Hi tradecode, 

Thank you for contacting Syncfusion support. 

We have checked checked your query “SfDataGrid exception when the collection changes during a Sort operation” at our end. We are attempting to replicate the reported issue on our end. It is, however, working as expected. You stated that you do default sorting for the underlying collection and that you frequently change the underlying collection. Please provide us some more details with a code snippet or video illustration to replicate the reported issue if feasible. It will be more helpful for us to find the exact cause for the issue and to provide a prompt solution at earlier. 

Balamurugan Thirumalaikumar  



Loader.
Up arrow icon