Advice on overriding ProcessSourceCollectionChanged()

I want to override the ProcessSourceCollectionChanged with my own implentation. Is it safe to do the following and not call the base implementation in GridCellSelectionController? My implementation will commit the current edit and clear all selections.

        protected override void ProcessSourceCollectionChanged(NotifyCollectionChangedEventArgs e, CollectionChangedReason reason)
        {
            // End cell edit and validate
            if (CurrentCellManager.HasCurrentCell && DataGrid.View is { IsEditingItem: true })
            {
                CurrentCellManager.CheckValidationAndEndEdit();
            }


            ClearSelections(false);
}

4 Replies

SB Sweatha Bharathi Syncfusion Team February 7, 2025 01:29 PM UTC

Hi Zia ,

We have reviewed your query and, based on the code snippet you provided, we understand that you want to clear all selections in the grid when the collection is changed. In the base implementation, when the selected data is removed from the maintained collection, the data is removed from the selection, and the SelectionChanged event is raised. In your implementation, you can clear the selections, and that will work fine. However, without calling the base, the SelectionChanged event will not be triggered for this scenario.
In general, if the base implementation is required first, use it first, and then your custom implementation will take effect.  Use the base implementation as needed to meet your requirements. If you encounter any issues regarding this, feel free to raise .


Regards,
Sweatha.B


WI WilliamCBegley February 13, 2025 05:51 AM UTC

I was also making a similar mistake, but now everything is resolved. Thank you.



MS Malini Selvarasu Syncfusion Team February 14, 2025 02:37 PM UTC

Hi  Zia ,

We are glad that your issue has been resolved. If you have any further questions, please don't hesitate to let us know.

Regards,
Malini Selvarasu


WI WilliamCBegley May 19, 2025 10:44 AM UTC

Overriding ProcessSourceCollectionChanged is useful when you need to customize how the grid responds to changes in the data source. For example, you might want to preserve selection, apply custom filters, or update UI elements when items are added or removed. Ensure that your override handles different NotifyCollectionChangedAction cases (Add, Remove, Reset, etc.) appropriately. Also, consider the CollectionChangedReason to distinguish between user actions and programmatic changes. Be cautious to avoid performance issues or unintended side effects, especially with large datasets. Testing with various data change scenarios can help ensure stability and correctness. I have explained everything in the given link: https://www.filemail.com/d/rppqyyfewaihxqr


Loader.
Up arrow icon