Xceed ( http://wpftoolkit.codeplex.com/ )が提供する Extended WPF Toolkit Community Edition で利用できる優れた DataGrid を使用しようとしています。レポートの結果を単純な DataGridControl オブジェクトに表示するアプリケーションがあります。ユーザーはレポートのリストからレポートを選択でき、データ グリッドはレポートに関連付けられた DataTable を使用して動的に更新されます。各レポートの DataTable の列は、名前と数量の両方が異なる場合があります。WPF の既定のコントロールでは、通常の MVVM データ バインディングを使用して問題なく動作します。これは、データの並べ替えまたはグループ化に列が使用されている場合を除いて、 Xceed の DataGridControl でも正常に機能します。
列がソートまたはグループ化され、DataTable がその列を含まないものに更新されると、DataGridControl は、ソートされている列が存在しないことを示す ArgumentException をスローします。例外の例を次に示します。
System.ArgumentException was
unhandled Message='' タイプには 'SAP_MATERIAL_NUMBER' という名前のプロパティがないため、データ コレクションを並べ替えることができません。
Source=PresentationFramework StackTrace: System.Windows.Data.BindingListCollectionView.ConvertSortDescriptionCollection(SortDescriptionCollection sorts) で System.Windows.Data.BindingListCollectionView.RefreshOverride() で System.Windows.Data.CollectionView.Refresh() で System.Windows.Data. System.Windows.Controls.ItemCollection.SetCollectionView(CollectionView ビュー) で System.Windows.Controls.ItemCollection.SetItemsSource(IEnumerable 値) で System.Windows.Data.CollectionView.DeferHelper.Dispose() で CollectionView.EndDefer()。 Windows.Controls.ItemsControl.OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) ...
コントロールを定義してバインドする現在の XAML は次のとおりです。
<xcdg:DataGridControl
Grid.Row="2"
AutoCreateColumns="True"
AutoRemoveColumnsAndDetailConfigurations="True"
ReadOnly="True"
x:Name="xceedReportResult"
ItemsSource="{Binding SelectedReport.Report.Result}"
FontSize="11">
<xcdg:DataGridControl.View>
<xcdg:TableflowView
ShowRowSelectorPane="False"
IsAnimatedColumnReorderingEnabled="True"
HorizontalGridLineBrush="LightGray"
VerticalGridLineBrush="LightGray"
IsAlternatingRowStyleEnabled="True"
ShowScrollTip="False">
<xcdg:TableflowView.Theme>
<xcdg:ClassicSystemColorTheme />
</xcdg:TableflowView.Theme>
</xcdg:TableflowView>
</xcdg:DataGridControl.View>
</xcdg:DataGridControl>
... Xceed フォーラムからのアドバイスに従って、SortDescriptions または GroupDescriptions をクリアすることを期待して、新しいレポートが選択されたときに次のコードを実行しようとしましたが、これは正しく機能しません。
ICollectionView source = xceedReportResult.ItemsSource as DataGridCollectionView;
if (source != null)
{
if (source.SortDescriptions != null)
{
source.SortDescriptions.Clear();
}
if (source.GroupDescriptions != null)
{
source.GroupDescriptions.Clear();
}
}
このデータ グリッドをこのように使用して、この問題を回避する方法を見つけた人はいますか?