Tag Archives: IList

Keeping the Selected Item Selected When Changing a ListView’s ItemsSource

, , ,

A ListView’s data display needs to be updated. The revised dataset, retrieved from the service layer, is contained in a new collection containing new object instances. Setting this IList<T> as the control’s new ItemsSource causes the control to display the revised data and…whoa…clears the currently selected item.

From the technical perspective, this clearing makes sense. A new collection has been displayed making the selected item from the previous collection irrelevant. However, from the user’s perspective, the same collection is displayed both before and after the refresh (albeit with revised data), so the current item selection is still pertinent and should be maintained.

Continue reading