2011-10-17 42 views
3

http://www.codeproject.com/KB/WPF/WpfDataVirtualization.aspxWPFデータ仮想化とデータグリッド

これは、ListViewコントロールで正常に動作します。

が、私は、DataGridコントロール(AsyncVirtualizationCollection)でそれを使用するとき、それは例外をスローします:

「値がnull、パラメータ名にすることはできません。キー」私は、原因とどのようにあるものではないん

それが起こるのを止める。 DataGridコントロールの編集機能が必要です

+0

こんにちは、 AttilahはDataGridで上記の例を変換または使用する方法を教えていただけますか? 私は完全にWPF –

答えて

3

辞書を使用していますか?デバッグし、ヌル値を辞書にキーとして追加しようとしているかどうかを確認します。 または、挿入しようとする空のキーを持つGridviewにDataKeyNamesパラメータがあるかどうかを確認します。

データを読み書きする場所(F10/F11)でデバッグしてください。 Visual Studioでローカルウィンドウを見てください。

+0

に感謝しています。それはまさに問題でした。 – Attilah

+0

問題ありませんでした。うれしいです。 – juFo

0

この例外は実際にはDataGridItemAttachedStorageクラスで発生していることがわかりました。 ここにいくつかのコールスタックフレームがあります。誰かがそれについての手がかりを与えることができることを願っています。

mscorlib.dll!System.Collections.Generic.Dictionary<object,System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object>>.FindEntry(object key) 未知 
    mscorlib.dll!System.Collections.Generic.Dictionary<object,System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object>>.TryGetValue(object key, out System.Collections.Generic.Dictionary<System.Windows.DependencyProperty,object> value) 未知 

    PresentationFramework.dll!System.Windows.Controls.DataGridItemAttachedStorage.TryGetValue(object item, System.Windows.DependencyProperty property, out object value) 未知 
    PresentationFramework.dll!System.Windows.Controls.DataGridRow.RestoreAttachedItemValue(System.Windows.DependencyObject objectWithProperty, System.Windows.DependencyProperty property) 未知 
    PresentationFramework.dll!System.Windows.Controls.DataGridRow.SyncProperties(bool forcePrepareCells) 未知 
    PresentationFramework.dll!System.Windows.Controls.DataGridRow.PrepareRow(object item, System.Windows.Controls.DataGrid owningDataGrid) 未知 
    PresentationFramework.dll!System.Windows.Controls.DataGrid.PrepareContainerForItemOverride(System.Windows.DependencyObject element, object item) 未知 
    PresentationFramework.dll!System.Windows.Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer(System.Windows.DependencyObject container, object item) 未知 
3

私もこれに遭遇しました。これは、問題は(AsyncVirtualizingCollectionの基本クラス)VirtualizingCollectionこのコードであったが判明:

public T this[int index] 
{ 
    // snip 

    // defensive check in case of async load 
    if (_pages[pageIndex] == null) 
     return default(T); 

    // snip 
} 

Tが参照型である場合、default(T)nullあり、DataGridがヌル行オブジェクトを理解しません。

は、これを解決するために、私は、デフォルト値を保持するためにVirtualizingCollectionにパブリックプロパティを追加しました:

public T DefaultValue = default(T);

をしてDefaultValue代わりのdefault(T)を返すために上記のコードを変更しました。その後、AsyncVirtualizingCollectionを作成すると、読み込み中に表示されるダミーオブジェクトにDefaultValueを設定します。

+0

これは本当に正解です。ありがとう! – blins