如何选中/取消选中复选框 [英] How to check/uncheck in checkbox
问题描述
我需要帮助!
我有两个复选框,分别是:Book和另一个:CD.
表单加载后,默认书被检查.现在我要检查CD,但是发生的事是书和CD都被检查了.
但我想就像我单击CD时一样,应该取消选中书,而当我单击书时,则应该取消选中CD,在一种情况下,如果我希望同时单击Book和CD,则都应该同时单击.
我曾尝试使用单选按钮,但在单选按钮中,有时无法同时检查Book和CD.
I want some help!!
I have two check box named :Book and another :CD.
After form load default Book is checked.Now i want to check CD, but what happens is that both book and CD are check.
But i want like as when i click on CD, book should be unchecked, and when i click on book, then CD should be unchecked and in one case if i wish to click both Book and CD then both should be clicked.
I have tried using radio button but in radio button ,both Book and CD are not check at the sometime.
Can somebody help me out?
推荐答案
在这种情况下,您仍然需要使用单选按钮:
您需要其中的3(三):1)CD,2)书籍,3)两者.
保持简单!
—SA
In this exact case, you still need to use radio buttons:
You need 3 (three) of them: 1) CD, 2) Book, 3) Both.
Keep it simple!
—SA
when i click on CD, book should be unchecked, and when i click on book, then CD should be unchecked
到目前为止一切都很好.
现在,当您说in one case if i wish to click both Book and CD then both should be clicked.
您如何看待呢?选中一个复选框,取消选中其他复选框.因此,从逻辑上讲,您永远无法选中两个复选框.
保持完整的第一个要求的唯一方法是使用另一个控件触发两个选项的触发检查,例如另一个复选框,同时检查". (在先前的答案中已经描述了如何使用事件进行操作).
我希望你能理解我的意思.如果您有任何疑问,请告诉我.
干杯
Ankur
when i click on CD, book should be unchecked, and when i click on book, then CD should be unchecked
So far so good.
Now when you say,in one case if i wish to click both Book and CD then both should be clicked.
How do you think that will be possible? Checking a checkbox, un-checks other. So you could logically never check both the checkboxes.
The only way you could do this keeping your 1st requirement intact is trigger check both option using a different control, say another checkbox which says ''Check Both''. (The way how to do it using events is already described in the previous answers).
I hope you understand what I am saying. Let me know if you have any doubts.
Cheers
Ankur
你好
如果您有3个项目(书籍,镉和两者):
Hello
If you have 3 Items (Book, Cd, Both):
private void Both_CheckedChanged(object sender, EventArgs e)
{
Book.Checked = true;
Cd.Checked = true;
}
private void Book_CheckedChanged(object sender, EventArgs e)
{
if (!Both.Checked)
Cd.Checked = !Book.Checked;
if (!Book.Checked)
Both.Checked = false;
}
private void Cd_CheckedChanged(object sender, EventArgs e)
{
if (!Both.Checked)
Book.Checked = !Cd.Checked;
if (!Cd.Checked)
Both.Checked = false;
}
这篇关于如何选中/取消选中复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!