I want to raise the:
private void txtbox_startdate_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{}
Function from a key leave event. The leave event looks like:
private void开发者_运维问答 txtbox_startdate_Leave(object sender, EventArgs e)
{}
The trouble is of course if I try and call it in this manner:
txtbox_startdate_Validating(sender, e)
An error is raised because in this case e
is an EventArg
s whereas the validation function wants a System.ComponentModel.CancelEventArgs
and so, how do I convert EventArgs
to a System.ComponentModel.CancelEventArgs
or create one so that I can call my validation function?
See MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.validating.aspx
You have no need to call the txtbox_startdate_Validating
event (or any other control with a validating event) from the txtbox_startdate_Leave
event as it's the order of the events to go from one to another as part of the design.
normally whatever the validator is, you can just call Validate() on it instead of doing this.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basevalidator.validate.aspx
Otherwise, just 'new' the canceleventargs yourself - it's not special, the constructors are public.
http://msdn.microsoft.com/en-us/library/system.componentmodel.canceleventargs.canceleventargs.aspx
精彩评论