c# - Radio Button Validation in WinForms -
so have multiple different radio buttons, in different group boxes. before user able "save" form, fields need filled in. trying make sure radio buttons filled in. @ moment trying use following code:
if (!(this.roundtrip.checked || this.oneway.checked)) { messagebox.show("select option trip type"); if (!(this.northrad.checked || this.expressrad.checked || this.expressrad.checked)) { messagebox.show("select option route type"); } if (!(this.yesneeded.checked || this.notneeded.checked)) { messagebox.show("select option accessibility"); } if (this.adultnum.value == 0 && this.seniornum.value == 0 && this.childnum.value == 0) { messagebox.show("select @ least 1 ticket"); } return; }
with code not allowing me click on save button, no message boxes come up. , after fill in radio boxes cannot click save button. appreciated.
your logic seems correct but, return @ last line. maybe need this;
private void btnsave_clicked() { if (!isvaliddataentered()) return; save(); } private bool isvaliddataentered() { if (!(this.roundtrip.checked || this.oneway.checked)) messagebox.show("select option trip type"); else if (!(this.northrad.checked || this.expressrad.checked || this.expressrad.checked)) messagebox.show("select option route type"); else if (!(this.yesneeded.checked || this.notneeded.checked)) messagebox.show("select option accessibility"); else if (this.adultnum.value == 0 && this.seniornum.value == 0 && this.childnum.value == 0) messagebox.show("select @ least 1 ticket"); else return true; return false; }
Comments
Post a Comment