Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListBox, DataView, And DataTable.RejectChanges()

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.

like image 291
Dummy01 Avatar asked Dec 14 '25 14:12

Dummy01


1 Answers

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?

like image 103
blindmeis Avatar answered Dec 17 '25 07:12

blindmeis