Update Listbox after inserting a row into database

Update Listbox after inserting a row into database

如此安好 发布于 2021-11-27 字数 970 浏览 828 回复 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.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!

如果你对这篇文章有疑问,欢迎到本站 社区 发帖提问或使用手Q扫描下方二维码加群参与讨论,获取更多帮助。



需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。


雨的味道风的声音 2022-06-07 1 楼

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.