Multiheckbox列表框的可用工具 [英] Available tool for Multicheckbox listbox
本文介绍了Multiheckbox列表框的可用工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好
是否有工具可以选择(选中)列表框中的多个项目,并选择"全部选择"选项。
Is there a tool for selecting (checking) multiple items in a listbox with a "Select all" option.
推荐答案
简单的解决方案是使用如下代码的按钮。
The simple solution would be to have a button with code like below.
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, true);
}
以下选择全部切换。它可以改进我做得相当快。
The following does a select all toggle. It can be improved on I did rather fast.
using System;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public class CheckedListBoxSelectAll :CheckedListBox
{
public CheckedListBoxSelectAll()
{
Items.Add("Select All");
ItemCheck += CheckedListBoxSelectAll_ItemCheck;
}
private void CheckedListBoxSelectAll_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.Index == 0)
{
ItemCheck -= CheckedListBoxSelectAll_ItemCheck;
var state = Convert.ToBoolean(e.NewValue);
for (var i = 1; i < Items.Count; i++)
{
SetItemChecked(i, state);
}
ItemCheck += CheckedListBoxSelectAll_ItemCheck;
}
}
/// <summary>
/// We should override Items.Clear
/// </summary>
public void Clear()
{
Items.Clear();
Items.Add("Select All");
}
}
}
这篇关于Multiheckbox列表框的可用工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文