Here's a simpler approach that can be reused for multiple lists.
private void listView_ItemCheck(object sender, ItemCheckEventArgs e) { var listView = sender as ListView; if (listView != null) { for (var i = 0; i < listView.CheckedItems.Count; i++) { listView.CheckedItems[i].Checked = false; } } }
The ItemCheck event is fired before the state of a list item changes, so no additional tests are required.
ItemCheck - Indicates that the item will change its state. The value is not updated until an event occurs.
Other answers that check if the current element does not match the current element are not useful, since the selection occurs after the completion of this event, so it does not matter if the value is false.
lastItemChecked != listView.Items[e.Index]
source share