title: Exception thrown when Xceed DataGridControl is bound to a DataTable and a sorted column no longer exists
body: <p>I am trying to use the excellent DataGrid available in the Extended WPF Toolkit Community Edition made available by Xceed (<a href="http://wpftoolkit.codeplex.com/" rel="nofollow">http://wpftoolkit.codeplex.com/</a>). I have an application that displays the results from reports in a simple DataGridControl object. The user can select the report from a list of reports and the data grid dynamically updates using a DataTable associated to the report. The columns in each Report's DataTable can vary both in name and quantity. With the default controls in WPF this works just fine using regular MVVM data binding. This also works fine with the DataGridControl from Xceed, <strong>except for when a column has been used to sort or group the data.</strong></p>
  
  <p>What happens is when a column is sorted or grouped, and the DataTable is updated to one that doesn't have the column in it, the DataGridControl throws an ArgumentException saying the column being sorted doesn't exist. Here's an example exception:</p>
  
  <blockquote>
    <p>System.ArgumentException was unhandled<br>
    Message='' type does not have property named 'SAP_MATERIAL_NUMBER', so cannot sort data
    collection.<br>
    Source=PresentationFramework   StackTrace:
           at System.Windows.Data.BindingListCollectionView.ConvertSortDescriptionCollection(SortDescriptionCollection
    sorts)
           at System.Windows.Data.BindingListCollectionView.RefreshOverride()
           at System.Windows.Data.CollectionView.Refresh()
           at System.Windows.Data.CollectionView.EndDefer()
           at System.Windows.Data.CollectionView.DeferHelper.Dispose()
           at System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView
    view)
           at System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable
    value)
           at System.Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject
    d, DependencyPropertyChangedEventArgs e)
           ...</p>
  </blockquote>
  
  <p>Here's my current XAML that defines and binds the control:</p>
  
  <pre><code>&lt;xcdg:DataGridControl
      Grid.Row="2"
      AutoCreateColumns="True"
      AutoRemoveColumnsAndDetailConfigurations="True"
      ReadOnly="True"
      x:Name="xceedReportResult"
      ItemsSource="{Binding SelectedReport.Report.Result}"
      FontSize="11"&gt;
  
      &lt;xcdg:DataGridControl.View&gt;
          &lt;xcdg:TableflowView
              ShowRowSelectorPane="False"
              IsAnimatedColumnReorderingEnabled="True"
              HorizontalGridLineBrush="LightGray"
              VerticalGridLineBrush="LightGray"
              IsAlternatingRowStyleEnabled="True"
              ShowScrollTip="False"&gt;
  
              &lt;xcdg:TableflowView.Theme&gt;
                  &lt;xcdg:ClassicSystemColorTheme /&gt;
              &lt;/xcdg:TableflowView.Theme&gt;
          &lt;/xcdg:TableflowView&gt;
      &lt;/xcdg:DataGridControl.View&gt;
  
  &lt;/xcdg:DataGridControl&gt;
  </code></pre>
  
  <p>...following some advice from the Xceed forums I've tried running the following code when a new report is selected in hopes of clearing out any SortDescriptions or GroupDescriptions, but this isn't working right:</p>
  
  <pre><code>ICollectionView source = xceedReportResult.ItemsSource as DataGridCollectionView;
  
  if (source != null)
  {
      if (source.SortDescriptions != null)
      {
          source.SortDescriptions.Clear();
      }
  
      if (source.GroupDescriptions != null)
      {
          source.GroupDescriptions.Clear();
      }
  }
  </code></pre>
  
  <p>Has anyone used this data grid in this way, and found a way around this issue?</p>