2

I am using an ICollectionView to display a list of items within a 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. 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.

Has anyone come across this issue before and found a solution for this issue?

Thomas Huber
  • 1,282
  • 1
  • 13
  • 23

2 Answers2

0

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;
Hamed
  • 2,084
  • 6
  • 22
  • 42
0

Instead of calling ICollectionView.Refresh() you can implement INotifyPropertyChanged interface in class you use in collection. Call PropertyChanged whenever any of displayed properties change.

Miroslav Hrivik
  • 822
  • 13
  • 16