测试复选框是否已选中

时间:2015-04-10 20:44:10

标签: c# while-loop

问题

如何不断检查是否已选中复选框,如果是,请执行某些操作。

如果未勾选则撤消更改。

我尝试了什么

 public Form1()
        {
            InitializeComponent();
            statusCmb.Text = "All";


           while (advancedQueryCb.Checked == true)
           {

                statusCmb.Text = null;
                String SQL = "SELECT * FROM bd;


            }

        }

2 个答案:

答案 0 :(得分:3)

您可以订阅Checked属性值更改时将会引发的复选框的CheckedChangedEvent

public Form1()
{
    InitializeComponent();
    statusCmb.Text = "All";
    advancedQueryCb.CheckedChangedEvent += (sender, e) => 
    {
        var checkbox = (CheckBox)sender;
        if (checkbox.Checked)
        {
            // The checkbox has been checked, so you can perform the 
            // necessary logic here
        }
    };
}

答案 1 :(得分:2)

那是什么事件

    public Form1()
    {
        InitializeComponent();
        advancedQueryCb.CheckedChanged += advancedQueryCb_CheckedChanged;
    }

    void advancedQueryCb_CheckedChanged(object sender, EventArgs e)
    {
        tatusCmb.Text = null;
        String SQL = "SELECT * FROM bd;
    }