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.
comboBox.SelectedIndex = -1; works for me.
Are you doing anything else in your event handler? Are you using databinding?
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?