We are currently using a single grid to display data for multiple "tabs" (in reality a restyled listbox where we bind a new data source to the grid when the selected item changes).
Different tabs can have different columns displayed, so we regenerate the collection of GridViewDataColumn objects whenever tab is switched. We always set IsCustomSortingEnabled to true on these objects. We then hook the SortingRequested event and refetch our data whenever a column header is clicked and the collection of sorting criteria changes. This works fine when a column header is clicked, but breaks when we switch to a tab that was previously sorted.
When we switch to a previously sorted tab, we regenerate the GridViewDataColumn collection (setting IsCustomSortingEnabled to true as ever), clear SortDescriptions on the grid and repopulate it with the correct SortDescription objects.
The problem is that setting these SortDescription's appears to trigger the RadGridView's native sorting mechanism, at which point it complains that our domain objects don't implement IComparable. I've attached the stack trace at the end of this post.
So it looks as if somewhere in the grid code IsCustomSortingEnabled is not being checked.
All help gratefully received
Regards
Chris
-----------------
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
at Telerik.Windows.Data.Grouping.NullValuesComparer`1.Compare(Object x, Object y)
at Telerik.Windows.Data.Grouping.SortDescriptionComparer`1.CompareWithIndexes(Int32 xIndex, TElement xElement, Int32 yIndex, TElement yElement)
at Telerik.Windows.Data.Grouping.SortDescriptionsComparer`1.CompareWithIndexes(Int32 xIndex, TElement xElement, Int32 yIndex, TElement yElement)
at Telerik.Windows.Data.Grouping.DataSourceIndexComparer`1.Compare(Int32 x, Int32 y)
at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
at System.Linq.EnumerableSorter`1.QuickSort(Int32[] map, Int32 left, Int32 right)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_UnfilteredIndexes()
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_DataSourceIndexes()
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_Count()
at Telerik.Windows.Data.VirtualizingRecordCollection.get_Count()
at Telerik.Windows.Data.VirtualizingRecordCollection.System.Collections.ICollection.get_Count()
at MS.Internal.Data.IndexedEnumerable.GetNativeIsEmpty(Boolean& isEmpty)
at MS.Internal.Data.IndexedEnumerable.get_IsEmpty()
at System.Windows.Data.CollectionView.get_IsEmpty()
at System.Windows.Data.CollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.RefreshOrDefer()
at System.Windows.Data.CollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at Telerik.Windows.Data.VirtualizingRecordCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.VirtualizingRecordCollection.OnCollectionReset()
at Telerik.Windows.Data.VirtualizingRecordCollection.Reset()
at Telerik.Windows.Data.VirtualizingRecordCollection.set_RealRecords(IList`1 value)
at Telerik.Windows.Data.RecordManager.RecalculateGroups()
at Telerik.Windows.Data.RecordManager.SortDescriptions_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Epro.ClientControls.Entity.DataGrid.EntityGridSortHandler.SetSortedColumnHeaders(ICollection`1 sortDescriptions, IEnumerable`1 propertiesToDisplay) in C:\Epro4Trunk\Epro.ClientControls\Entity\DataGrid\EntityGridSortHandler.cs:line 63
Different tabs can have different columns displayed, so we regenerate the collection of GridViewDataColumn objects whenever tab is switched. We always set IsCustomSortingEnabled to true on these objects. We then hook the SortingRequested event and refetch our data whenever a column header is clicked and the collection of sorting criteria changes. This works fine when a column header is clicked, but breaks when we switch to a tab that was previously sorted.
When we switch to a previously sorted tab, we regenerate the GridViewDataColumn collection (setting IsCustomSortingEnabled to true as ever), clear SortDescriptions on the grid and repopulate it with the correct SortDescription objects.
The problem is that setting these SortDescription's appears to trigger the RadGridView's native sorting mechanism, at which point it complains that our domain objects don't implement IComparable. I've attached the stack trace at the end of this post.
So it looks as if somewhere in the grid code IsCustomSortingEnabled is not being checked.
All help gratefully received
Regards
Chris
-----------------
at System.Collections.Comparer.Compare(Object a, Object b)
at System.Collections.Generic.ObjectComparer`1.Compare(T x, T y)
at Telerik.Windows.Data.Grouping.NullValuesComparer`1.Compare(Object x, Object y)
at Telerik.Windows.Data.Grouping.SortDescriptionComparer`1.CompareWithIndexes(Int32 xIndex, TElement xElement, Int32 yIndex, TElement yElement)
at Telerik.Windows.Data.Grouping.SortDescriptionsComparer`1.CompareWithIndexes(Int32 xIndex, TElement xElement, Int32 yIndex, TElement yElement)
at Telerik.Windows.Data.Grouping.DataSourceIndexComparer`1.Compare(Int32 x, Int32 y)
at System.Linq.EnumerableSorter`2.CompareKeys(Int32 index1, Int32 index2)
at System.Linq.EnumerableSorter`1.QuickSort(Int32[] map, Int32 left, Int32 right)
at System.Linq.EnumerableSorter`1.Sort(TElement[] elements, Int32 count)
at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_UnfilteredIndexes()
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_DataSourceIndexes()
at Telerik.Windows.Data.Grouping.DataRecordList`1.get_Count()
at Telerik.Windows.Data.VirtualizingRecordCollection.get_Count()
at Telerik.Windows.Data.VirtualizingRecordCollection.System.Collections.ICollection.get_Count()
at MS.Internal.Data.IndexedEnumerable.GetNativeIsEmpty(Boolean& isEmpty)
at MS.Internal.Data.IndexedEnumerable.get_IsEmpty()
at System.Windows.Data.CollectionView.get_IsEmpty()
at System.Windows.Data.CollectionView.RefreshOverride()
at System.Windows.Data.CollectionView.RefreshInternal()
at System.Windows.Data.CollectionView.RefreshOrDefer()
at System.Windows.Data.CollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at Telerik.Windows.Data.VirtualizingRecordCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.VirtualizingRecordCollection.OnCollectionReset()
at Telerik.Windows.Data.VirtualizingRecordCollection.Reset()
at Telerik.Windows.Data.VirtualizingRecordCollection.set_RealRecords(IList`1 value)
at Telerik.Windows.Data.RecordManager.RecalculateGroups()
at Telerik.Windows.Data.RecordManager.SortDescriptions_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Telerik.Windows.Data.RadObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
at Telerik.Windows.Data.RadObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Epro.ClientControls.Entity.DataGrid.EntityGridSortHandler.SetSortedColumnHeaders(ICollection`1 sortDescriptions, IEnumerable`1 propertiesToDisplay) in C:\Epro4Trunk\Epro.ClientControls\Entity\DataGrid\EntityGridSortHandler.cs:line 63