如何验证组框中的单选按钮 [英] how to validate radiobutton in a groupbox

查看:85
本文介绍了如何验证组框中的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,

我在验证组框中的单选按钮时遇到问题.
一个分组框中有4个单选按钮,现在我要检查该分组框中是否没有选中的单选按钮...
等到以下组框.
然后单击重置按钮后,我要取消选中所有单选按钮.

请帮忙...

感谢进阶....

Hellow Guys,

I''m a having a problem in validating radiobuttons in a groupbox.
There are 4 radiobuttons in a groupbox, now i want to check if there is no checked radiobuttons in the groupbox...
and so on to the following groupboxes.
Then after a click a reset button i want to unchecked all the radiobuttons.

Please help...

Thanks in advanced....

推荐答案

好吧,您尚未说明尝试过的内容,尝试时出现的问题是什么.

看看有关单选按钮如何分组的这些文章:
Gropu单选按钮 [如何对RadioButton进行分组 [
Well, you have not stated what you have tried and where was the issue when you tried it.

Have a look at these article on how radio buttons are grouped:
Gropu Radio Button[^]
How to group RadioButtons[^]

They are more than enough to understand the logic which can be used for coding your scenario.

UPDATE:
Ok. Fine, try this: (it''s in C# that I am writing):
// Do this for getting checked status of all radio buttons
// Similar approch can be done to RESET an uncheck them all
for(int i=0;i<myGroupBox.Controls.Count;i++)
{
   RadioButton rb= (RadioButton)myGroupBox.Controls[i];
   if(rb.checked==true)
   {
      // do whatever
      // use break; if needed
      // increase a counter if you want number
   }
}


遍历组框的子级,并检查它们是否是1)单选按钮和2)未选中的.
Iterate over the children of the groupboxes and check if they are 1) radiobuttons and 2) unchecked.


这篇关于如何验证组框中的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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