Bohn
Bohn

Reputation: 26919

Overriding the combobox events

Is it the wrong way I am doing this: - first I created a class inheriting from Combobox and I am gonna override some events, so something like this:

public override void  SelectedIndexChanged(object sender, EventArgs e)

but it tells me : "There is no suitable method for override"

Thanks

Upvotes: 1

Views: 2224

Answers (2)

Adam Houldsworth
Adam Houldsworth

Reputation: 64467

You cannot override events. Instead you will find a method called OnSelectedIndexChanged, override this.

Upvotes: 1

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

You should override the method OnSelectedIndexChanged instead. The On[EventName] methods are the ones that raises the events. What you should do is to override that method, do the extra things you want to do and then call base.OnSelectedIndexChanged(e) when you want to raise the event:

protected override void OnSelectedIndexChanged(EventArgs e)
{
    // do extra stuff here
    base.OnSelectedIndexChanged(e);
    // perhaps you want to do something after the event 
    // handlers have been invoked as well
}

Upvotes: 2

Related Questions