如何在单击按钮时取消选择面板中所有选定的单选按钮? [英] how deselect all selected radiobuttons in a panel on a button click ?

查看:61
本文介绍了如何在单击按钮时取消选择面板中所有选定的单选按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在单击按钮时取消选择面板中所有选定的单选按钮?

how deselect all selected radiobuttons in a panel on a button click?

推荐答案

如果使用

RadioButtonList有一个方法ClearSelection。



protected void Save_Click(object sender,EventArgs e)

{

RadioButtonList1.ClearSelection(); < br $>
}



这将解决您的问题。







代码问题是在互斥的单选按钮组中,您需要先选择其中一个。



所以,我相信有两种方法可以解决这个问题:



保持单选按钮。添加无按钮到集合,这样就好像没有选择其他三个。并且最初选择此无。按钮。



将单选按钮更改为复选框,因此用户可以选择并取消选择每个按钮。然后实现自己的排除逻辑。我不推荐这个。
If you use
RadioButtonList has a method ClearSelection.

protected void Save_Click(object sender, EventArgs e)
{
RadioButtonList1.ClearSelection();
}

This will resolve your issue.

or

The code problem is that in a mutually exclusion radio buttons group you need to initially select one of them.

So, I believe there are two ways of solving the problem:

Keep the radio buttons groud. Add a "none" button to the set, so that it works as if none of the other three are selected. And initially select this "none" button.

change the radio buttons to check boxes, so the user might select and deselect each of them. Then implement your own exclusion logic. I don't recommend this one.


If (control.CheckedStatus == CheckedStatus.Checked)
{
   control.CheckedStatus = CheckedStatus.Unchecked;
}







或其他方式你可以使用代表。






or other way you can use delegates.

delegate void CheckOrUncheckRadioButtonEventHandler(RadioButton rb, bool isChecked);
        private void CheckOrUncheckRadioButton(RadioButton rb, bool isChecked)
        {
            try
            {
                if (rb.InvokeRequired)
                {
                    CheckOrUncheckRadioButtonEventHandler d = new CheckOrUncheckRadioButtonEventHandler(CheckOrUncheckRadioButton);
                    this.Invoke(d, new object[] { rb, isChecked });
                }
                else
                {
                    rb.Checked = isChecked;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }









问候,

Praveen Nelge





Regards,
Praveen Nelge


这篇关于如何在单击按钮时取消选择面板中所有选定的单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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