I'm trying to do a validation wherein if a checkbox has been ticked, the corresponding textbox would no longer be in ReadOnly
mode and should not be empty. For example, if I checked CheckBox1
, if TextBox1
did not have any input, a MessageBox
would pop up to say that "Please fill up the entire form!". Else, it would display "Done!".
This is what I have so far:
if ((CheckBox1.Checked && TextBox1.Text == "")
|| (CheckBox2.Checked && TextBox2.Text == ""))
MessageBox.Show("Please fill up the entire form!");
else if (CheckBox1.Checked && TextBox1.Text != "")
MessageBox.Show("Done!");
else if (CheckBox2.Checked && TextBox2.Text != "")
MessageBox.Show("Done!");
I've made a couple of checkboxes/textboxes that would require this validation and I find that it gets kind of lengthy so I was wondering if there's a simpler/better approach.
(not sure if relevant) Note: I got the toggling the ReadOnly mode when the CheckChanged event is triggered part down