I am doing some validation functions for my project, but I'm stuck. I want to have one function to handle several different controls and errors.
Here is my code:
private void ValidateControls(Control c)
{
if (c is TextBox)
{
if (c.Text == "")
{
epNew.SetError(c, "Something");
}
}
else if (c is ComboBox)
{
}
}
And I call it this way:
private void txtNEAN_Validating(object sender, CancelEventArgs e)
{
ValidateControls(txtNEAN);
}
This is great for text fields. But if I do this:
private void cbbEMerk_Validating(object sender, CancelEventArgs e)
{
ValidateControls(cbbEMerk);
}
if (c.SelectedItem == null)for example, does not work.
How can i achieve this? And is it normal to use? If not, what is the best alternative?
I would love to hear something!
source
share