winforms - How can I validate only the controls inside a panel? -


i have form 2 panels each have [save] button.

how can validate of controls inside each panel separately?

i hoping panel class have validate() method doesn't. it's not containercontrol doesn't have validatechildren method.

what's best way accomplish this?

if set form's autovalidate mode enableallowfocuschange, , presuming have validating events hooked each of controls inside panel, this:

private void tb_validating(object sender, canceleventargs e) {     textbox tb = sender textbox;     if (tb != null)     {         if (tb.text == string.empty)         {             errorprovider1.seterror(tb, "textbox cannot empty");             e.cancel = true;         }         else             errorprovider1.seterror(tb, "");                         } } 

then on click handler save button, can this:

private void savebutton_click(object sender, eventargs e) {     foreach (control c in panel1.controls)        c.focus();     // if want summarise errors     stringbuilder errorsummary = new stringbuilder();     foreach (control c in panel1.controls){         string error = errorprovider1.geterror(c);         if (error != string.empty)              errorsummary.appendformat("{0}{1}", errorprovider1.geterror(c), environment.newline);     }     if(errorsummary.length>0)         messagebox.show(errorsummary.tostring()); } 

that cause validation fire on each of controls within panel.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -