the answer is not quite complete, the solution I found was:
Private NextSelectionChangedIsTriggeredByCode As Boolean = False
Private Sub MyListView_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
If NextSelectionChangedIsTriggeredByCode Then
NextSelectionChangedIsTriggeredByCode = False
Return
End If
If ... Some reason not to change the selected item ... Then
Dim MessageBoxResult = MessageBox.Show("Changes were made and not saved. Continue Anyway ?", "Unsaved Changes", MessageBoxButton.OKCancel)
If MessageBoxResult = MessageBoxResult.Cancel Then
NextSelectionChangedIsTriggeredByCode = True
MyListView.SelectedIndex = MyListView.Items.IndexOf(e.RemovedItems(0))
Return
End If
End If
... Code to execute when selection could change ...
e.Handled = True
End Sub
source
share