CheckBox limiting. [modified]
-
So I hope this has a Simple answer. I have a program with 6 Options, they can be either RadioButtons or CheckBoxs, But I need to know how to limit the options to 3 or less? Is there an easy way to do this with out checking how many are true and building a checker?
modified on Thursday, October 15, 2009 11:15 AM
-
So I hope this has a Simple answer. I have a program with 6 Options, they can be either RadioButtons or CheckBoxs, But I need to know how to limit the options to 3 or less? Is there an easy way to do this with out checking how many are true and building a checker?
modified on Thursday, October 15, 2009 11:15 AM
Hi, I have no idea what you mean by ControlButtons, did you mean CheckBoxes? Anyway, the only way I know would be to attach this same handler to each of the relevant Controls; then either have a collection that holds the relevant controls or tag them somehow so you can easily enumerate them:
void CheckedChanged(object sender, EventArgs e) {
int count=0;
foreach(Control c in relevantControls) {
RadioButton rb=c as RadioButton;
if (rb!=null) count++;
}
if (count>MAX) {
RadioButton rb=sender as RadioButton;
if (rb!=null) rb.Checked=false;
}
}:)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
-
Hi, I have no idea what you mean by ControlButtons, did you mean CheckBoxes? Anyway, the only way I know would be to attach this same handler to each of the relevant Controls; then either have a collection that holds the relevant controls or tag them somehow so you can easily enumerate them:
void CheckedChanged(object sender, EventArgs e) {
int count=0;
foreach(Control c in relevantControls) {
RadioButton rb=c as RadioButton;
if (rb!=null) count++;
}
if (count>MAX) {
RadioButton rb=sender as RadioButton;
if (rb!=null) rb.Checked=false;
}
}:)
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
Yea I meant CheckBoxs or RadioButtons sorry, and yea I was looking for a way other than that.
-
Yea I meant CheckBoxs or RadioButtons sorry, and yea I was looking for a way other than that.
You have your answers, But let me tell you there is big difrance betwen CheckBox and RadioBox You can have a lot of checkBoxex. Each check box can be true or false If you have more than 1 RadioBox, you can set it to true to ONLY ONE. To seperate betwen radioboxex (aka Grouping) place it in a panel Edit: You can't check it without programming it. You need to check how many has ben set to true. There is no build in functions for your request