tags:

views:

1196

answers:

2

I have a ComboBox in WPF whose ItemsSource is set to a list programatically. 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.

+2  A: 

comboBox.SelectedIndex = -1; works for me.

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

chris
No, I'm not using any data binding. Just double checked.
Bob
Try to do a 'find all references' for comboBox and comment out the code to find the problem.
chris
+1  A: 
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?

configurator