I have a combo box and a button. When I click the button, it's supposed to change the selected value and then fire the code when the item was changed. Unfortunately, the selection changed event fires before I set the selected value of the combo box.
My Combo Box's code on initialize:
ListCB.SelectedValuePath = "Key";
ListCB.DisplayMemberPath = "Value";
ListCB.Items.Add(new KeyValuePair<int, string>(1, "One"));
ListCB.SelectedValuePath = "Key";
ListCB.DisplayMemberPath = "Value";
ListCB.Items.Add(new KeyValuePair<int, string>(2, "Two"));
ListCB.SelectedValuePath = "Key";
ListCB.DisplayMemberPath = "Value";
ListCB.Items.Add(new KeyValuePair<int, string>(3, "Three"));
My Button's code:
ListCB.SelectedValue = 3;
My Selection Changed Event:
private void ListCB_Change(object sender, SelectionChangedEventArgs e)
{
MessageBox.Show("Value is now: " + ListCB.SelectedValue);
}
What happens is if for example I select 1 from the combo box and click the button, it will say Value now is: One instead of Three.
Am I using the wrong event? Or am I using a wrong way to change the selected value?