Problem with sorting

2 posts, 0 answers
  1. Andrew
    Andrew avatar
    20 posts
    Member since:
    Mar 2010

    Posted 20 Oct 2011 Link to this post

    I have got 2 GridView controls: one shows details of a selected row from the other grid. Grid with details has sorting on 3 columns (by default) – image 1. When I change row in master grid, I have got an exception (problem with sorting in the details grid) – image 2:

    Object reference not set to an instance of an object.
       w Telerik.Windows.Controls.GridView.AggregatesToGroupFooterAggregatesConverter.<>c__DisplayClass4.<Convert>b__1(AggregateResult f)
       w System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
       w MS.Internal.EnumerableCollectionView.LoadSnapshotCore(IEnumerable source)
       w MS.Internal.EnumerableCollectionView.LoadSnapshot(IEnumerable source)
       w MS.Internal.EnumerableCollectionView.RefreshOverride()
       w System.Windows.Data.CollectionView.Refresh()
       w Telerik.Windows.Controls.GridView.GridViewFooterCell.AggregateResults_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
       w Telerik.Windows.Controls.GridView.GridViewDataControl.CreateAggregateResults()
       w Telerik.Windows.Controls.GridView.GridViewDataControl.OnItemsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
       w Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
       w Telerik.Windows.Data.QueryableCollectionView.RefreshOverride()
       w Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer()
       w Telerik.Windows.Data.QueryableCollectionView.InvalidatePagingAndRefresh()
       w Telerik.Windows.Data.QueryableCollectionView.OnSortDescriptorsCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.RadObservableCollection`1.ResumeNotifications()
       w Telerik.Windows.Data.CollectionHelper.Reset(IEnumerable source, IList target, Func`2 itemConverter)
       w Telerik.Windows.Data.ObservableCollectionManager.HandleCollectionChanged(IList sender, NotifyCollectionChangedEventArgs args)
       w Telerik.Windows.Data.ObservableCollectionManager.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs args)
       w Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)
       w System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
       w System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w Telerik.Windows.Data.ObservableItemCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
       w System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
       w Telerik.Windows.Data.RadObservableCollection`1.ClearItems()
       w Telerik.Windows.Data.ObservableItemCollection`1.ClearItems()
       w System.Collections.ObjectModel.Collection`1.Clear()
       w Dashboard.WidgetsClass.GridClass.GridClass.SetColumns(IList data, ObservableCollection`1 kolumny)
       w Dashboard.WidgetsClass.GridClass.GridClass.GetDataCompleted(Object sender, GetDataSetDataCompletedEventArgs e)

    After data is loaded I reset SortDescriptors, GroupDescriptors and FilterDescriptors. I think that this is the cause of the problem (it stopped working after I upgraded my project to Telerik 2011.2.920.1040):

    Telerik.Windows.Data.GroupDescriptorCollection group = new Telerik.Windows.Data.GroupDescriptorCollection();
    Telerik.Windows.Data.SortDescriptorCollection sort = new Telerik.Windows.Data.SortDescriptorCollection();
    Telerik.Windows.Data.FilterDescriptorCollection filter = new Telerik.Windows.Data.FilterDescriptorCollection();
     
    void dataGrid_Sorted(object sender, GridViewSortedEventArgs e)
    {
         sort.Clear();
         foreach (var sd in dataGrid.SortDescriptors)
              sort.Add(sd);
    }
     
     
    void dataGrid_Filtered(object sender, GridViewFilteredEventArgs e)
    {
         filter.Clear();
         foreach (var fd in dataGrid.FilterDescriptors)
              filter.Add(fd);
    }
     
     
    void dataGrid_Grouped(object sender, GridViewGroupedEventArgs e)
    {
         group.Clear();
         foreach (var g in dataGrid.GroupDescriptors)
              group.Add(g);
    }
     
    // After loading data:
    try
    {
         if (sort != null)
         {
              dataGrid.SortDescriptors.Clear();
              foreach (var sd in sort)
                   dataGrid.SortDescriptors.Add(sd);
         }
         if (group != null)
         {
              dataGrid.GroupDescriptors.Clear();
              foreach (var gd in group)
                   dataGrid.GroupDescriptors.Add(gd);
         }
         if (filter != null)
         {
              dataGrid.FilterDescriptors.Clear();
              foreach (var fd in filter)
                   dataGrid.FilterDescriptors.Add(fd);
         }
    }
    catch
    {
    }

    Any suggestions?

  2. Vera
    Admin
    Vera avatar
    265 posts

    Posted 21 Oct 2011 Link to this post

    Hi Andrew,

    Actually, we had a similar issue and it should be resolved. So I would suggest you to download our Latest Internal Build and see if it's working for you.

    Best wishes,
    Vera
    the Telerik team
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
Back to Top