c# - If else statement textbox error -
i trying create if else statement show message box if no input.
if(textbox1.text==false) { messagebox.show("please fill in boxes") }
i have 16 different text box out, need use if else statement each?
pass textboxes
in list , loop it
//create list once in constructor of main form or window list<textbox> list = new list<textbox>() //... list.add(textbox1); list.add(textbox2);' //... loop foreach(textbox txt in list) { if(string.isnullorwhitespace(txt.text)) { messagebox.show("please fill in boxes"); break; } }
update
if textboxes expecting number/double input use tryparse
checking if value valid
foreach(textbox txt in list) { double temp; if(double.tryparse(txt.text, temp) == true) { //save or use valid value debug.print(temp.tostring()); } else { messagebox.show("please fill in boxes"); break; } }
Comments
Post a Comment