开发者

How to filter on a constantly updated collection displayed in grid?

开发者 https://www.devze.com 2023-01-10 00:02 出处:网络
Let\'s say I have a WPF application that shows \"questions\". Questions can have different statuses, such as \"open\", and \"answered\". The questions are stored in an ObservableCollection and display

Let's say I have a WPF application that shows "questions". Questions can have different statuses, such as "open", and "answered". The questions are stored in an ObservableCollection and displayed on a DataGrid.

I want to have a toggle button at the top that switches between "open" and "answered" questions. When a user clicks the "open" button, 开发者_如何学Pythonthe grid should display only open questions, and when a user clicks the "answered" button, it should display only answered questions.

These objects are constantly being updated by another thread (every second). In addition, their status can be changed from another thread, and the grid would need to be updated.

What is a good way to filter on this collection? Right now I am using ICollectionView and calling Refresh() when a question's status changes, but I am getting errors due to calling refresh while "AddItem/EditItem" transaction occurring.

Thanks.


I would suggest that you just lock the calls to Refresh and the adding & editing of items to prevent the two threads conflicting and causing the errors

0

精彩评论

暂无评论...
验证码 换一张
取 消