简体   繁体   English

ICollectionView键盘索引在刷新时重置

[英]ICollectionView keyboard index resets on Refresh

I am using an ICollectionView to display a list of items within a ListView. 我正在使用ICollectionView在ListView中显示项目列表。 I have come across an issue I do not seem to be able to find a solution for. 我遇到了一个似乎无法解决的问题。

The selection works fine as long as one only uses the mouse. 只要一个人仅使用鼠标,该选择就可以正常工作。 To always display the up to date information I use the ICollectionView.Refresh() method from time to time. 为了始终显示最新信息,我会不时使用ICollectionView.Refresh()方法。 However this results in an issue when using the keyboard arrows to navigate through the list of items. 但是,这在使用键盘箭头浏览项目列表时会导致问题。

No matter at which position the current SelectedIndex is at, as soon as I call Refresh() the next time one presses an arrow key the selected item is the item at position 0 of the ListView. 无论当前SelectedIndex处于哪个位置,在我下次调用Refresh()时一次按下箭头键时,所选项目都是ListView位置0的项目。

Has anyone come across this issue before and found a solution for this issue? 之前有没有人遇到过这个问题并找到解决方案?

Do this when you want to refresh the listview: 要刷新列表视图时,请执行以下操作:

//store the selected items
ListView.SelectedListViewItemCollection collection;
collection = listView1.SelectedItems;

// refresh the list view
listView1.Refresh();

//now select them again
foreach (ListViewItem item in collection)
    item.Selected = true;

Instead of calling ICollectionView.Refresh() you can implement INotifyPropertyChanged interface in class you use in collection. 您可以在集合中使用的类中实现INotifyPropertyChanged接口,而不是调用ICollectionView.Refresh()。 Call PropertyChanged whenever any of displayed properties change. 每当显示的任何属性更改时,调用PropertyChanged。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM