Welcome to the Xceed Community | Help
Community Search  
More Search Options

Handling collection-changed events

Sort Posts: Previous Next
  •  10-09-2008, 9:42 AM Post no. 28136

    Handling collection-changed events

    The following example demonstrates how to subscribe to the CollectionChanged event of the DataGridCollectionView.SortDescriptions collection's INotifyCollectionChanged interface implementation to be notified when sorting applied to a grid's columns changes.

    VB.NET

    Protected Overrides Sub OnInitialized(ByVal e As EventArgs)
      MyBase.OnInitialized(e)

      Dim view As DataGridCollectionView = TryCast(Me.OrdersGrid.ItemsSource, DataGridCollectionView)
      AddHandler (CType(view.SortDescriptions, INotifyCollectionChanged)).CollectionChanged, AddressOf SortCollectionChanged
    End Sub

    Private Sub SortCollectionChanged(ByVal sender As Object, ByVal e As NotifyCollectionChangedEventArgs)
      Debug.WriteLine("Sort changed")
    End Sub

    C#

    protected override void OnInitialized( EventArgs e )
    {
      base.OnInitialized( e );

      DataGridCollectionView view = this.OrdersGrid.ItemsSource as DataGridCollectionView;
      ( ( INotifyCollectionChanged )view.SortDescriptions ).CollectionChanged += new NotifyCollectionChangedEventHandler( this.SortCollectionChanged );
    }

    private void SortCollectionChanged( object sender, NotifyCollectionChangedEventArgs e )
    {
      Debug.WriteLine( "Sort changed" );
    }

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.