So far, I cannot explain the observed behavior, but have found a relatively simple workaround:
private void cbAdmDvc_SelectionChanged( object sender, SelectionChangedEventArgs e ) { if( cbAdmDvc.SelectedIndex < 0 ) return; DvcType tiDvc;
Stupid, but it works because .SelectedItem set correctly.
As I said, this is the only ComboBox experiencing such oddities from several ...
EDIT, 2014-Oct-21 :
After making some changes to the application logic, it suddenly turned out that I was considering the same problem with another ComboBox. The potential solution found was combobox-selectedvalue-not-update-from-binding-source , but when I tried to set the initial values โโvia .SelectedItem instead of .SelectedValue , it turned out even .SelectedValue / worse. So I also tried applying my previous solution, and it worked!
Here is my attempt to explain the observed behavior:
Setting the initial value to the code ( CBox.SelectedValue= smth; ) raises the CBox_SelectionChanged event. For some reason, reading .SelectedValue at this point returns null (as if it is not ready yet), however reading .SelectedItem seems wonderful! Once you exit CBox_SelectionChanged , the event code can correctly read .SelectedValue .
So, if you 1 ) have a _SelectionChanged event _SelectionChanged , 2 ) refer to .SelectedValue inside it and 3 >) set the initial selection via .SelectedValue somewhere else in the code - watch out for null and protect the code! NTN !! :)
source share