Check-Box使用C#作为单选按钮作出反应 [英] Check-Box react as Radio Button using C#

查看:224
本文介绍了Check-Box使用C#作为单选按钮作出反应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个要求在组框中添加三个复选框,并且复选框必须作为单选按钮作出反应,即

1.一次只能检查一个复选框。

2.当用户去检查另一个复选框时,前一个复选框应该是未选中的。

我也知道这不是一个好方法,这对非技术或技术用户来说真的很混乱,但我也想学习一些新的东西。



我经历了很多网站,但我没有得到任何令人满意的解决方案。我希望我能从你那里得到一个好的。



感谢和问候,

Ravindra。

解决方案

制作一个复选框列表,并对所有复选框使用相同的事件处理程序。

每当选择一个时,将其索引存储在临时变量中,使所有复选框都未选中,然后检查你存储的那个。


首先,如果你知道这不是一个好的解决方案,你就不应该这样做。给你这个要求的人可能不够称职,所以你需要说服他/她。这是你的职责之一,也是非常困难的职责之一。这就像预防犯罪一样。



这是一件好事,寻找解决方案是个坏主意。这些事情应该从第一原则开始,使用原始文档。难怪你找不到任何东西 - 这对于写这篇文章或者只是答案的文章来说太过微不足道了。



此外,你甚至没有说明什么是 CheckBox 。哪一个?你认为这个名字只有一种吗?不。这个名字含糊不清,所以你真的需要给我们提供完整的姓名。在所有情况下,您只需处理更改检查状态时调用的事件,并更改处理程序中的属性。



-SA

Hi All,

I have one requirement to add three check box in a group box, and check-box must react as radio button i.e.,
1. one can check only one check-box at a time.
2. when user goes to check another check box, previous one automatically should be unchecked.
I also know that this is not a good approach to do this, and it's really confusing to non-technical or technical user but I also want to learn something new in this.

I went through lots of sites, but I didn't get any satisfactory solution. I hope I will get good one from you.

With Thanks and Regards,
Ravindra.

解决方案

Make a List of Checkboxes and use the same event handler for all of them.
Whenever one is selected store it's index in temp variable, make all checkboxes 'unchecked', then check the one you stored.


First of all, if you know this is not a good solution, you should not do it. The person who gave you this "requirement" could be not competent enough, so you need to convince him/her. This is one of your responsibilities, one of the pretty difficult ones. This is like preventing crime.

It it was a good thing to do, looking for a solution would be a bad idea. Such things should be done from first principles, using original documentation. No wonder you could not find anything — this is way too trivial to write and article on this, or just an answer.

Besides, you did not even indicate what is CheckBox. Which one? Do you think there is only one type with this name? No. This name is ambiguous, so you really need to give us full type name. In all cases, you simply handle the event invoked when a checked state is changed, and change properties in the handler.

—SA


这篇关于Check-Box使用C#作为单选按钮作出反应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆