We can't see your picture, but ... that code doesn't do what you expect it to - the
break
command in a loop exits the loop immediately.
So your code exits the loop during the first time round because it the textbox is empty it executes a
break
, and if it isn't it also executes a
break
. So it only ever looks at the first textbox.
And your code doesn't look at any comboboxes at all!
Plus, this structure is silly:
if (string.IsNullOrEmpty(txt.Text))
{
...
}
else if (!string.IsNullOrEmpty(txt.Text))
{
...
}
As it's easier to read and has exactly the same effect as this:
if (string.IsNullOrEmpty(txt.Text))
{
...
}
else
{
...
}
If you want to check all the textboxes, removes the
break
from both sides.
If you want to exit after the first empty textbox, remove the break from the
else
condition code block.
And consider using
string.IsNullOrWhitespace[
^] instead of empty, or a space in a text box is counted as "not empty".