A method has an input parameter that is a forms control object (say a ComboBox). I want to determine if the control has a particular event registered and, if so, trigger the event. I tried to enter the following code but the compiler rejects it because the selected event (in the example SelectedIndexChanged) can only appear to the left of the += or -= operators.
private void DoSearch(ComboBox cb) {
// Once the search is complete, I want to call the event
// Does this control have a SelectedIndexChanged event registered?
if (cb.SelectedIndexChanged != null) {
// call the event
cb.SelectedIndexChanged(cb, EventArgs.Empty);
}
}