I have a function that I use to validate the contents of some text boxes after the user browses for a directory.
private void CheckValidation(object sender, EventArgs e)
{
bool OK = true;
if (PhotograherNumber.Text == string.Empty || errorProvider1.GetError(PhotograherNumber)!="")
{
OK = false;
}
if (EventNumber.Text == string.Empty || errorProvider1.GetError(EventNumber)!="")
{
OK = false;
}
if (OK)
{
EnableProcessNow();
}
else
{
DisableProcessNow();
}
}
That works great.
But then I added the function to be called by the Validated event on the text box.
Once I did that it created this:
private void CheckValidation()
{
}
Again this is no issue for the Validated Event. However, in another section of my program I call the function CheckValidation();. But when I do that it doesn’t call the correct one.
Obviously if I delete the empty
private void CheckValidation()
{
}
Then I get the error ‘No Overload for Method CheckValidation takes 0 Arguments’.
So how do I call the correct CheckValidation from within my code but still ensure that I can still call it from the events?
From what I understand of your question is you want to run the same method, but both be able to call it manually without parameters and allow it to be an event handler?
If you want to call the handler method from your code you can just call
CheckValidation(null, EventArgs.Empty);– however a better solution is put the code in theCheckValidation()overload (without the parameters) and call that from the handler: