Programmatically Clear Selection in WPF ComboBox


I have a ComboBox in WPF whose ItemsSource is set to a list programmatically. How would I go about clearing the selection in an event handler? I've tried:

comboBox.SelectedIndex = -1;
comboBox.SelectedItem = null;
comboBox.SelectedValue = null;
comboBox.SelectedValue = "";

None of them have any effect.

11/2/2018 12:15:38 PM

Accepted Answer

comboBox.SelectedIndex = -1; works for me.

Are you doing anything else in your event handler? Are you using databinding?

10/19/2012 9:18:55 PM

comboBox.SelectedIndex = -1;

Is the way to go. I don't know why it doesn't work for you; perhaps an event handler for SelectedIndexChanged changes the value?

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow