views:

21

answers:

2

I have made a custom class by inheriting a DateTimePicker and made some methods that allow it to be blank/null.

If the control is blank and a user clicks on it, it populates with the current date. It also raises the ValueChanged event.

If the control is populated and a user presses delete, it clears and sets its value to null, but the ValueChanged event doesn't trigger.

In the control's OnKeyDown method, I would like to include some code that raises the ValueChanged event, but there doesn't seem to be a way to do that.

Do I need to override the base class event? Is there an applicable example?

+1  A: 

You have to call/override DateTimePicker.OnValueChanged(). This method calls the event, so you can implement your code through this.

Femaref
+2  A: 

DateTimePicker.OnValueChanged will raise the ValueChanged event.

Quartermeister
This seems to work: `base.OnValueChanged(new EventArgs());` - though I am not sure whether the event arguments should be anything in particular.
JYelton
@JYelton: You can use EventArgs.Empty to avoid creating a new object. The ValueChanged event doesn't pass any information in its EventArgs, so it doesn't matter what object you provide.
Quartermeister