How to add or remove an item from a CollectionViewSource?

故事扮演 提交于 2020-01-11 09:42:12

问题


I want to bind a datagrid.itemsource to a List with anonymous type,so i bind it to a collectionViewSource,but i need to add or remove an item to the list,but i don't know how?


回答1:


CollectionView and CollectionViewSource are, as their name suggest, only views. You can only manipulate the original collection. You should use an ObservableCollection if you want the changes to be automatically reflected in your UI.

I would advise against using anonymous types for data binding. But if you must - they implement the Equals method, so you should be able to remove items using new items with equal properties or using the item's index.



来源:https://stackoverflow.com/questions/11823341/how-to-add-or-remove-an-item-from-a-collectionviewsource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!