checkedListBox筛选器

本文介绍了一个使用C#实现的列表框操作示例,包括如何将数据从一个列表框转移到另一个列表框,以及如何设置列表框内项的选择状态。通过几个简单的函数实现了全选转移、选择性转移及鼠标点击选中等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 ///转移全部
        private void buttonSendAll2Nosend_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBoxSend.Items.Count; i++)
            {
                this.checkedListBoxSiftEmail.Items.AddRange(this.checkedListBoxSend.Items);
                this.checkedListBoxSend.Items.Clear();
            }
        }

        private void buttonNosendToSendAll_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBoxSiftEmail.Items.Count; i++)
            {
                this.checkedListBoxSend.Items.AddRange(this.checkedListBoxSiftEmail.Items);
                this.checkedListBoxSiftEmail.Items.Clear();
            }
        }

        private void buttonSendChoickedToNosend_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBoxSend.Items.Count; i++)
            {
                if (checkedListBoxSend.GetItemChecked(i))
                {
                    this.checkedListBoxSiftEmail.Items.Add(checkedListBoxSend.GetItemText(checkedListBoxSend.Items[i]));
                    this.checkedListBoxSend.Items.RemoveAt(i);
                }
            }
        }

        ///转移选中行
        private void buttonNosendToSend_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < this.checkedListBoxSiftEmail.Items.Count; i++)
            {
                if (checkedListBoxSiftEmail.GetItemChecked(i))
                {
                    this.checkedListBoxSend.Items.Add(checkedListBoxSiftEmail.GetItemText(checkedListBoxSiftEmail.Items[i]));
                    this.checkedListBoxSiftEmail.Items.RemoveAt(i);
                }
            }
        }

        ///设置选中行勾选
        private void checkedListBoxSend_MouseClick(object sender, MouseEventArgs e)
        {
            this.checkedListBoxSend.SetItemChecked(this.checkedListBoxSend.SelectedIndex,true);
        }

        private void checkedListBoxSiftEmail_MouseClick(object sender, MouseEventArgs e)
        {
            this.checkedListBoxSiftEmail.SetItemChecked(this.checkedListBoxSiftEmail.SelectedIndex, true);
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值