simple radio button question
-
Another newbie needing help.... I need to 2 radio (or text) buttons so that both cannot be on at the same time.
private void radioButton1_CheckedChanged(object sender, EventArgs e) { radioButton2.Checked = false; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { radioButton1.Checked = false; }
But it doesn't work when I have On radioButton1 OFF radioButton2 and when I click on radioButton2, radio button1 goes off but radiobutton2 also remains off. Do I have a circular event? -
Another newbie needing help.... I need to 2 radio (or text) buttons so that both cannot be on at the same time.
private void radioButton1_CheckedChanged(object sender, EventArgs e) { radioButton2.Checked = false; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { radioButton1.Checked = false; }
But it doesn't work when I have On radioButton1 OFF radioButton2 and when I click on radioButton2, radio button1 goes off but radiobutton2 also remains off. Do I have a circular event?Hi, 1. if one rb is checked, and for some reason gets unchecked, then you also uncheck the other, hence both will be unchecked, which is NOT what you want. 2. no this is not circular, since a "changed" event only fires when the value CHANGES, not when a value gets assigned that equals the current value. 3. If you put your rb's in a GroupBox, then they behave like real rb's automatically (at most one checked). :)
Luc Pattyn [My Articles]
-
Another newbie needing help.... I need to 2 radio (or text) buttons so that both cannot be on at the same time.
private void radioButton1_CheckedChanged(object sender, EventArgs e) { radioButton2.Checked = false; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { radioButton1.Checked = false; }
But it doesn't work when I have On radioButton1 OFF radioButton2 and when I click on radioButton2, radio button1 goes off but radiobutton2 also remains off. Do I have a circular event?The CheckedChanged event is raised when the radio button is checked or unchecked. The problem with your code above is that: Assuming 1 was previously checked when 2 is clicked, a checkedchanged for 2 is raised,which unchecked 1 this raises checkedchanged for 1 which also disables 2. At such both are disable (The scenario above assumes that the control are in different containers) You could use this code
private void radioButton1_CheckedChanged(object sender, EventArgs e) { radioButton2.Checked = !radioButton1.Checked; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { radioButton1.Checked = !radioButton2.Checked; }
-
Another newbie needing help.... I need to 2 radio (or text) buttons so that both cannot be on at the same time.
private void radioButton1_CheckedChanged(object sender, EventArgs e) { radioButton2.Checked = false; } private void radioButton2_CheckedChanged(object sender, EventArgs e) { radioButton1.Checked = false; }
But it doesn't work when I have On radioButton1 OFF radioButton2 and when I click on radioButton2, radio button1 goes off but radiobutton2 also remains off. Do I have a circular event?