选中框(已选中/未选中) [英] Checked Box(checked/unchecked all)

查看:104
本文介绍了选中框(已选中/未选中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用c#选择/取消选择所有checkedListBox1(windows窗体)



我想要一个checkbox1包含所有选中/未选中的命令。怎么写请帮忙......



<前lang =cs> 私人 void checkBox1_CheckedChanged( object sender,EventArgs e)
{
for int i = 0 ; i < checkedListBox1.Items.Count; i ++)
{
checkedListBox1.SetItemChecked(i, true );
}

}

private void checkBox2_CheckedChanged( object sender,EventArgs e)
{
for (< span class =code-keyword> int i = 0 ; i < checkedListBox1 .Items.Count; i ++)
{
checkedListBox1.SetItemChecked(i, false );
}
}

解决方案

使用 CheckBox.Checked Property [ ^ ]确定checkBox1的选中状态,然后:

 int  i =  0 ; i <  checkedListBox1.Items.Count; i ++)
checkedListBox1.SetItemCheckState(i,(checkBox1.Checked?CheckState.Checked:CheckState.Unchecked));


How to Select / Deselect All checkedListBox1 using c#(windows form)

I want to one checkbox1 contain all checked/unchecked command. How to write Please help......

private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, true);
            }

        }

        private void checkBox2_CheckedChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < checkedListBox1.Items.Count; i++)
            {
                checkedListBox1.SetItemChecked(i, false);
            }
        }

解决方案

use CheckBox.Checked Property[^] to determine the checked state of the checkBox1, then:

(int i = 0; i < checkedListBox1.Items.Count; i++)
      checkedListBox1.SetItemCheckState(i, (checkBox1.Checked ? CheckState.Checked : CheckState.Unchecked));


这篇关于选中框(已选中/未选中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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