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

Sort Event

Sort Posts: Previous Next
  •  02-17-2009, 9:30 AM Post no. 18675

    Sort Event

    Is there a sort event that gets called after the grid is sorted. I would like to use this to move the highlight to the first row in the grid, instead of following the currently highlighted row. Any help would be much appreciated.

    Thank you,

    Carlos

  •  02-17-2009, 9:40 AM Post no. 18676 in reply to 18675

    Re: Sort Event

     

    Hi Carlos,

    You can handle the CollectionChanged on the SortDescriptions of your view in order to implement a sort event that gets called after the grid is sorted.

    For example:

    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" );
    }

    The information was taken from the online documentation at: http://doc.xceedsoft.com/products/XceedWpfDataGrid/Sorting_Data.html.


    Xceed - Software Developer and Technical Support
  •  02-17-2009, 10:39 AM Post no. 18679 in reply to 18676

    Re: Sort Event

    Thank you for your speedy response. But when I try this I get an error that says, "Cannot change or check the contents or Current position of CollectionView while Refresh is being deferred." Do you know how I can get around this?

    Thank you,

    Carlos

  •  11-05-2009, 1:54 PM Post no. 24776 in reply to 18679

    Re: Sort Event

    I get the same message as well.  Has anybody come up with a work around?  What I'm trying to do is set the top row as the current row after a sort.
    Filed under:
  •  03-12-2010, 6:30 PM Post no. 26097 in reply to 24776

    Re: Sort Event

    Attempting to change the current item whilst the grid is being sorted will generate this exception.

    There is a very easy work around using BeginInvoke on the dispatcher, which allows for the sorting to complete before moving to the first item in the collection.

    private void SortCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
        DataGridCollectionView view = OrdersGrid.ItemsSource as DataGridCollectionView;
        OrdersGrid.Dispatcher.BeginInvoke((Action)delegate()
        {
            view.MoveCurrentToFirst();
        }, DispatcherPriority.Render, null);
    }

     

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