views:

243

answers:

1

I have bound a ListBox to a SQL CE database with this code:

ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:DatabaseWindow}}, Path=Database.Photos1}"

This ListBox is populated properly. But when I try to insert a row into the database (InsertOnSubmit + SubmitChagnes), the ListBox is not updated!

I have tried:

ListBox.Items.Refresh();

ListBox.GetBindingExpression(ListBox.ItemsSourceProperty).UpdateTarget();

ListBox.ItemsSource = null; 
ListBox.ItemsSource = this.Database.Table;

None of these helped. How can I update a ListBox?!

PS: After reloading the database, the row appears in the ListBox. PPS: If anyone knows a tutorial for SQL CE with WPF where the insertion into a ListBox is shown - that would be great, too!

A: 

Make sure the data you're assigning to the ItemsSource implements INotifyCollectionChanged. (e.g. You can put your items into an ObservableCollection) Also, for changes to your indvidual items to be reflected you must be implementing INotifyPropertyChanged.

M. Jahedbozorgan
Yeah, I know that's the reason why the ListBox is not updated *automatically*. But it would be enough if I could update it manually..
eWolf