tags:

views:

24

answers:

2

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

+2  A: 

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
}
Fredrik Mörk
+1 Good explanation, I didn't want to commit myself to saying those methods raised the events, I wasn't sure about that part :)
Adam
+1  A: 

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

Adam