---
title: "Q: When the SelectionChanged event gets raised, how do I get the new selection?"  
description: "Q: When the SelectionChanged event gets raised, how do I get the new selection?"  
author: "Anonymous User"  
published: 2011-03-12  
updated: 2020-09-18  
canonical: https://www.mindstick.com/interview/402/q-when-the-selectionchanged-event-gets-raised-how-do-i-get-the-new-selection  
category: "wpf"  
tags: ["wpf"]  
reading_time: 2 minutes  

---

# Q: When the SelectionChanged event gets raised, how do I get the new selection?

The SelectionChanged event is designed to handle controls that allow multiple selections,\
so it can be a little confusing for a single-selection selector such as ComboBox. The\
SelectionChangedEventArgs type passed to event handlers has two properties of type\
IList: AddedItems and RemovedItems. AddedItems contains the new selection and\
RemovedItems contains the previous selection.

e.g.\
void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)\
{\
if (e.AddedItems.Count > 0)\
object newSelection = e.AddedItems[0];\
}\
Like this code, never assume that there’s a selected item! Besides the fact that ComboBox’s\
selection can be cleared programmatically, it can get cleared by the user when IsEditable is\
true and IsReadOnly is false. In this case, if the user changes the selection box text to\
something that doesn’t match any item, the SelectionChanged event is raised with an\
empty AddedItems collection.

## Answers

### Answer by Anonymous User

The SelectionChanged event is designed to handle controls that allow multiple selections,\
so it can be a little confusing for a single-selection selector such as ComboBox. The\
SelectionChangedEventArgs type passed to event handlers has two properties of type\
IList: AddedItems and RemovedItems. AddedItems contains the new selection and\
RemovedItems contains the previous selection.

e.g.\
void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)\
{\
if (e.AddedItems.Count > 0)\
object newSelection = e.AddedItems[0];\
}\
Like this code, never assume that there’s a selected item! Besides the fact that ComboBox’s\
selection can be cleared programmatically, it can get cleared by the user when IsEditable is\
true and IsReadOnly is false. In this case, if the user changes the selection box text to\
something that doesn’t match any item, the SelectionChanged event is raised with an\
empty AddedItems collection.


---

Original Source: https://www.mindstick.com/interview/402/q-when-the-selectionchanged-event-gets-raised-how-do-i-get-the-new-selection

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
