3

I have a list box which is binded to a DataView.

<ListBox ItemsSource="{Binding Path=Categories}" DisplayMemberPath="Name"></ListBox>

where Categories is a property to class that inherits the INotifyPropertyChanged interface:

public class EditCategoriesPresenter : INotifyPropertyChanged
{
    private DataTable _TableOfCategories;

    public DataView Categories { get { return _TableOfCategories.DefaultView; } }

    ...
}

While all data changes to the underlying DataTable (row inserts and deletes, column value changes) are reflected to list box automatically, when I do a DataTable.RejectChanges() row changes are reflected but not column value changes.

I can understand why this is happening (the DataTable.RejectChanges does not raise any notifications for column value changes) but still cannot find any easy solution to solve it.

I also add the OnPropertyChanged("Categories") after DataTable.RejectChanges() but still no luck.

Any ideas?

Thank you in advance.

1 Answer 1

1

when i work with datatables i always use BindingListCollectionView for binding, cause wpf do this anyway implicitly. but now i can use the Refresh() method to refresh my ui binding.

public BindingListCollectionView Categories {get; private set;}

this.Categories = (BindingListCollectionView)CollectionViewSource.GetDefaultView(this._TableOfCategories);

//after reject
this.Categories.Refresh()

nevertheless, what does your ListBox looks like (just the xaml you posted or some datatemplates too)? can you post a screenshot?

3
  • Thank you very much! It works! My list box is so simple as in my XAML. But why you mentioned that? Is there any problem with this solution if I will use data templates?
    – Dummy01
    May 20, 2011 at 10:05
  • i just didnt use DisplayMemberPath="Name" with a listbox before, i always use DataTemplate. but its all fine :)
    – blindmeis
    May 20, 2011 at 10:33
  • Most of the time I also use data templates but for this list box which is really simple, I think DisplayMemberPath is the easiest way :)
    – Dummy01
    May 20, 2011 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.