ComboBox.SelectionChanged doesn't catch the first selection
I need to fill textboxes depending on the item selected in a combobox. I fill combo async and in Completed event I have the following cod开发者_Go百科e
combo.ItemsSource = e.Result;
combo.DisplayMemberPath = "Name";
combo.SelectedIndex = -1;
Then in the SelectionChanged event of the combo, I catch the selected object
MyClass mc= ((ComboBox)sender).SelectedItem as MyClass;
tbxName.Text = mc.Name;
...
However, when I load the project and select any event for the 1st time, NOTHING happens. Every other time (2nd, 3rd, nth) the data is correctly caught and displayed.
So I need to know why the combo doesn't catch the first selection? That's the reason I have the code combo.SelectedIndex = -1 (when the app loads, combo is empty - selection -1 works).
Solved by putting the code inside Completed event. Now I have delay in executing everything, but it works.
精彩评论