Good day to all, I want to locate all empty TextBox and ComboBox in easy way.
As you can see the image below if fields is empty they show message and red back color in which textbox or combobox is empty.
I try and something wrong, thank to those who can fix this problem.
TextBox[] textBox = { textBox1, textBox2};
ComboBox[] comboBox = { comboBox1, comboBox2 };
foreach (TextBox txt in textBox)
{
if (string.IsNullOrEmpty(txt.Text))//if all textbox is empty
{
txt.BackColor = Color.Red;
string message = "Required field empty.";
string tittle = "Error";
MessageBoxButtons button = MessageBoxButtons.OK;
DialogResult result = MessageBox.Show(message, tittle, button, MessageBoxIcon.Error);
break;
}
else if (!string.IsNullOrEmpty(txt.Text))//if not empty
{
txt.BackColor = Color.White;
MessageBox.Show("task complete");
break;
}
}
return;