If I'm understanding the question properly, you're essentially asking if the SelectedIndexChanged
event will be raised if you set the selected index programmatically.
The answer is yes. Setting the selected index of a combo box programmatically (e.g. by modifying the SelectedIndex
property in the constructor) will raise the SelectedIndexChanged
event, and therefore cause the code in your event handlers to be executed. If you set the selected index to 1, variableA
will be set to 0. If you set the selected index to 2, variableA
will be set to 1. Or whatever logic your code in the event handler method implements.
Of course, the SelectedIndexChanged
event is only raised when the selected index is changed. If you set the selected item to "item1" in the constructor, and then the user re-selects "item1", the event won't be fired again. But that's probably what you want. The value of variableA
wouldn't change anyway by your current logic.