如何通过单击一键来检查多个复选框 [英] How check many checkbox with one button click

查看:72
本文介绍了如何通过单击一键来检查多个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的WinForm上有大约40个CheckBoxes。每个CheckBox都有其独特的CheckBox.Text。 ListBox有15个文本项。与15个CheckBoxes相同。我想只检查名称在ListBox中的CheckBox。我想在这个CheckBox编码中使用foreach语句。任何人都可以尽快帮助我使用此代码。

解决方案

迭代复选框(例如,参见如何遍历表单上的所有复选框? [ ^ ])并且只检查那些其文本位于列表框中(请参阅ListBox.FindStringExact方法(字符串) ) [ ^ ])。


能够解决我的问题thnx的建议。



 str = ds.Tables [ 0 ]。行[ 0 ] [  genere]的ToString(); 
str = str.Replace( );
temptextbox.Text = str;
string [] stringArray = str.Split(' ');
templistbox.Items.AddRange(stringArray);
for int i = 0 ; i < templistbox.Items.Count; i ++)
{
templistbox.Text = templistbox.Items [i] .ToString( );
str = templistbox.Text;
foreach (控制c panel6.Controls)
{
if (c CheckBox)
{
if (c.Text == str)
{
CheckBox temp =(CheckBox)c;
temp.Checked = true ;

}
}
}
}


答案3对你有帮助

I have around 40 CheckBoxes on my WinForm. Each CheckBox has its unique CheckBox.Text. A ListBox has 15 text items. which are same as for 15 CheckBoxes. I want to check only those CheckBoxes whose Name are in ListBox. And I want to use foreach statement for this CheckBox coding. Can anyone help me with this code ASAP.

解决方案

Iterate on check boxes (see, for instance How can I iterate through all checkboxes on a form?[^]) and check only the ones whose text is found in the list box (see "ListBox.FindStringExact Method (String)"[^]).


able to solve my problem thnx for the suggestion's.

str = ds.Tables[0].Rows[0]["genere"].ToString();
    str = str.Replace(",", "");
    temptextbox.Text = str;
    string[] stringArray = str.Split(' ');
    templistbox.Items.AddRange(stringArray);
    for (int i = 0; i < templistbox.Items.Count; i++)
    {
        templistbox.Text = templistbox.Items[i].ToString();
        str = templistbox.Text;
        foreach (Control c in panel6.Controls)
        {
            if (c is CheckBox)
            {
                if (c.Text == str)
                {
                    CheckBox temp = (CheckBox)c;
                    temp.Checked = true;

                }
            }
        }
    }


Answer 3 Will Be Helpful to you


这篇关于如何通过单击一键来检查多个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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