how loop through multiple checkbox in C#

前端 未结 6 1055
后悔当初
后悔当初 2021-01-14 00:06

I have 100 checkbox in a winfrom. Their name is sequential like checkbox1,checkbox2 etc. I have a submit button in my winform. After clicking the submitting button, it check

6条回答
  •  臣服心动
    2021-01-14 00:50

    foreach (var control in this.Controls) // I guess this is your form
                {
                    if (control is CheckBox)
                    {
                        if (((CheckBox)control).Checked)
                        {
                            //update
                        }
                        else
                        {
                            //update another
                        }
                    }
                }
    

提交回复
热议问题