Reputation:
I have a ComboBox
which also gets controlled by two buttons. But I would like to separate the execution from using the ComboBox
dropdown and the buttons.
comboBox3.DropDownClosed += (b, f) =>
{
week = Convert.ToInt16(comboBox3.Text);
Console.WriteLine(week);
};
I tried this approach but it seems to be not updating the week when the dropdown gets closed and selecting another value.
Upvotes: 1
Views: 98
Reputation: 125197
If you want to do something when user changes the selected index of the ComboBox
, you need to handle SelectionChangeCommitted
event (and not SelectedIndexChanged
):
The
SelectionChangeCommitted
event is raised only when the user changes the combo box selection, and you can create a handler for this event to provide special handling for theComboBox
when the user changes the selected item in the list.
In the other hand, SelectedIndexChanged
will raise whenever the user or code changes the selected index.
So, instead of handling SelectedIndexChanged
, you should write different methods to do different things, for example, handle Button1.Click
and call Action1
, handle Button2.Click
and call Action2
and handle ComboBox.SelectionChangeCommitted
to detect when user changes the selected index and call Action3
.
Upvotes: 1