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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Can't connect to CollectionChanged

Thread ID:





132403 Aug 30,2017 05:24 PM UTC Sep 4,2017 04:41 PM UTC WPF 1
Tags: SfDataGrid
Brian Bell
Asked On August 30, 2017 05:24 PM UTC

I am using WPF SfDataGrid in MVVM application.

In response to a click from the user, the viewmodel needs the filtered records from the SfDataGrid. Using FilterChanged event, I can get the filtered records when the filter changes. However, the underlying collection might change (and change the filtered record set) between the time the filter was changed and when I need the filtered records.

I would like to use the CollectionChanged event, but I can't register a handler for it. In https://www.syncfusion.com/forums/120981/event-that-triggered-when-added-new-row, it shows adding the CollectionChanged handler during the Loaded event handling. In my case, the SfDataGrid.View property is null when datagrid_Loaded is called, so I can't add the new CollectionChanged handler.

How can I handle the CollectionChanged event?

It would be even better if I could do this in XAML. I've tried the following, but (perhaps not surprisingly) the command never gets executed.

     <i:EventTrigger EventName="CollectionChanged">
          <i:InvokeCommandAction Command="{Binding CollectionChangedCommand}"
                                             CommandParameter="{Binding ElementName=sfgrid }" />

Gnanasownthari Thirugnanam [Syncfusion]
Replied On September 4, 2017 04:41 PM UTC

Hi Brian, 

On analyzing your query, you can’t directly bind the collectionchanged event in XAML as like your given code snippet but you can listen the events of View from BindableView property setter as like below code example. 

<Syncfusion:SfDataGrid x:Name="datagrid"   
                               BindableView="{Binding View,Mode=TwoWay}" 
                               ItemsSource="{Binding OrderInfoCollection }"> 

private ICollectionViewAdv view; 
public ICollectionViewAdv View 
        return view; 
        view = value; 
        //You can listen the view events from here. 
            view.CollectionChanged += View_CollectionChanged; 
private void View_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) 
    //You can do your own logic here. 

We have prepared the sample based on your requirement, please find the sample from the below link and let us know if this helps you. 

Sample location: 
Gnanasownthari T. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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