开发者

WPF Listview with ListViewCollection - Listview not reflecting the collection's changes.

I have a listview that's bound to a ListCollectionView. The LCV has a single sortdescription at any time. I am updating the collection in this manner:

IEditableCollectionView IEditView = lvBatches.Items as IEditableCollectionView;

IEditView.EditItem(m_collectionView.CurrentItem);//I've also tried passing MyListView.SelectedItem
((TestData)IEditView.CurrentEditItem).start = frm.newDate;
((TestData)IEditView.CurrentEditItem).edited = true;
IEditView.CommitEdit();

However, when I do, nothing happens to the listview's items. If I re-sort the list, the changes are then reflected. A Refresh() on the collection also updates the listview, but that's like using a stick of dynamite to open a soda can, from what I gather.

Does anyone have any ideas. My above code looks like the examples I'm seeing around the 'n开发者_C百科et so I don't think that's the problem. Are there any common mistakes people make anyone is aware of, maybe something to do with the sorting? I had it working and now it's not and I have no idea what broke it.

Thanks in advance.


See my answer about creating a VeryObservableCollection.

The problem you are experiencing is that collections do not update with mere property changes -- CollectionChanged only fires if you add or remove elements. So you need to hook PropertyChanged and send a CollectionChanged when a property changes, which is what VeryObservableCollection does.


Are you calling NotifyPropertyChanged? If a Refesh() shows the correct values then most likely they are in the collection but the UI has to know to update value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜