I am binding the ItemsSource
property of a DataGrid
to a property in my ViewModel. I am then creating an ICollectionView
and creating a default view with the DataGrid
's item source like so:
_displayItemsView = CollectionViewSource.GetDefaultView(_displayItems);
where _displayItems
is a List
and _displayItemsView
is an ICollectionView
.
Now the problem I am having is that I am allowing users to filter the data grid like so:
_displayItemsView.Filter = delegate(object item)
{
DISPLAY_ITEM displayItem = (DISPLAY_ITEM)item;
if ((displayItem.RETAIL_ITEM_DPCI.ToString().ToUpper().Contains(value.ToUpper()))
.
.
.
This works most of the time just great, but if the user is currently editing or adding a row in the DataGrid
an un-handled exception is thrown by the ICollectionView
. How should I go about detecting if either:
- The
DataGrid
is currently being modified or - The
ICollectionView
is not in a state to be filtered?
Any guidance is appreciated, and I am open to ideas. Thanks!