Sorting abends

Apr 24, 2009 at 8:41 PM
I have a DataGrid that uses an ObservableCollection of business objects.  There is a property on the business object that refers to another business object.  I am using the following DataGridTextColumn:


<dg:DataGridTextColumn Binding="{Binding EquipmentType.Description}" Header="Category" Width="100" SortMemberPath="EquipmentType.Description"></dg:DataGridTextColumn>

The column displays the information, but when I try to sort the column by clicking on the column header, I get the following error:

System.InvalidOperationException was unhandled
  Message="The SortDescriptions added are not valid. The probable solutions are to set the CanUserSort on the Column to false, or to use SortMemberPath property on the Column, or to handle the Sorting event on DataGrid."
  Source="WPFToolkit"
  StackTrace:
       at Microsoft.Windows.Controls.DataGrid.DefaultSort(DataGridColumn column, Boolean clearExistingSortDescriptions) in D:\dd\WPF_TSV_2\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:line 6202
       at Microsoft.Windows.Controls.DataGrid.OnSorting(DataGridSortingEventArgs eventArgs) in D:\dd\WPF_TSV_2\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:line 6070
       at Microsoft.Windows.Controls.DataGrid.PerformSort(DataGridColumn sortColumn) in D:\dd\WPF_TSV_2\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:line 6100
.....
  InnerException: System.InvalidOperationException
       Message="Collection was modified; enumeration operation may not execute."
       Source="mscorlib"
       StackTrace:
            at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
            at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
            at System.Collections.Generic.List`1.Enumerator.MoveNext()
            at Microsoft.Windows.Controls.DataGrid.AddGroupingSortDescriptions() in D:\dd\WPF_TSV_2\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:line 6339
            at Microsoft.Windows.Controls.DataGrid.DefaultSort(DataGridColumn column, Boolean clearExistingSortDescriptions) in D:\dd\WPF_TSV_2\src\wpf\src\ControlsPack\WPFToolkit\DataGrid\Microsoft\Windows\Controls\DataGrid.cs:line 6195


Is this because of the '.' notation?
Dec 29, 2009 at 9:35 AM

Check the following link:

http://stackoverflow.com/questions/1645823/wpf-datagrid-sort-on-column-with-null-elements