Hello fellow developers,
I've created a control which derives from the .NET TextBox. I then
wanted to add two events to the new control, so I added the following
to the control code:
public event EventHandler InvalidValueMatched;
public event EventHandler ValidValueMatched;
But when one of the events is raised I get this exception:
System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="UserResponseControl"
StackTrace:
at
CustomControls.ValidationTextBox.OnValidating(Canc elEventArgs e)
at
System.Windows.Forms.Control.PerformControlValidat ion(Boolean
bulkValidation)
at
System.Windows.Forms.ContainerControl.ValidateThro ughAncestor(Control
ancestorControl, Boolean preventFocusChangeOnError)
By the way, I raise an event with the following code:
InvalidValueMatched.Invoke(this, new EventArgs());
How can this problem be solved? I have googled a lot, but none of the
tutorials/samples I can find, matches my scenario. Since I'm also
pretty new to custom controls, I'd like to know if I'm doing anything
wrong (ex. can I just pass a new EventArgs()?).
Thanks in advance!
- Dan