I got stuck in situations before the user interface in the Model changes, then the model change extends to the user interface and creates an endless loop. Are you dealing with something like that?
If so, then the only way out is to update the user interface from the model only if they differ. I.e:
if (comboBox.SelectedItem != newValue) comboBox.SelectedItem = newValue;
If this does not give you what you want, another option is to temporarily remove the event handler:
comboBox.SelectedIndexChanged -= this.comboBox_SelectedIndexChanged; comboBox.SelectedIndex = newIndex; comboBox.SelectedIndexChanged += this.comboBox_SelectedIndexChanged;
or, instruct the handler to ignore this event:
ignoreComboBoxEvents = true; comboBox.SelectedIndex = newIndex; ignoreComboBoxEvents = false; ... public void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if (ignoreComboBoxEvents) return; ... }
source share