I want to minimize the amount of code i have to write for this small problem. I have 1 textbox that has a relationship with 2 checkboxes as yes and no. The textbox on form load is set to disabled. When the yes checkbox is changed this event occurs –
private void checkYes1_CheckedChanged(object sender, EventArgs e)
{
textBox14.Enabled = true;
checkNo1_cbx.Checked = false;
}
and when the no checkbox is changed –
private void checkNo1_cbx_CheckedChanged(object sender, EventArgs e)
{
textBox14.Enabled = false;
checkYes1_cbx.Checked = false;
}
Although another problem is that i have to press yes twice to get it to check.
This is for a question on a form and so far it goes up to 11 questions and more will be added in the future. So my 2 problems so far is –
-
How can I fix the problem when the checkbox is changed I have to press it again to check it.
-
Is it possible to improve this code to minimize the amount of code i will have to write in the future.
However consider using
RadioBoxinstead ofCheckBoxbecause you want to if one being checked uncheck the other..Edit: In your previous design, you get it wrong
changed I have to press it again to check itbecause of you have two event handlers assigned to each of the check boxes. now at your code when the first one checked, you are disable the text box and make the other unchecked, but when you call the other uncheckedChecked = falseyou are calling the second check box event handler also so it will enable the text and make the first one disable… you should remove the event handler by-=when updating at your code if you don’t want the handler handler to be triggered again.. And that what I am doing in the code sample provided.