在C#中,一个checklistbox
我发现下面的不够好:如何在多个选中的列表框中限制选择?
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked && checkedListBox1.CheckedItems.Count >= 3)
e.NewValue = CheckState.Unchecked;
}
但是我有很多检查列表框,我想实现在所有这些不同的限制。比如我想限制我的checkedListBox1
只有3项选择,而checkedListBox2
将被限制在2个选择等等...
我试图使多个checkedListBox_ItemCheck
方法,但似乎没有影响checklistboxes的其余部分。它只影响我的第一个。任何人都可以帮助我吗?
非常感谢,我刚刚开始使用Windows窗体。
编辑:我希望这将使它更清楚我的目标是什么:
说我有以下checkedListBoxes
:checkedListBox1, checkedListbox2, checkedListBox3
这里就是我想要做的事:
checkedListBox1 = (/*limit the number of items users are able to select to only 3 items*/);
checkedListBox2 = (/*limit the number of items users are able to select to only 2 items*/);
checkedListBox3 = (/*limit the number of items users are able to select to only 4 items*/);
所以你有一个checkedListbox,你想限制你的用户只能检查限制数量的checkboxitems? – Niklas
我有几个checkedListBoxes,我想做一个函数来限制不同checkedListBoxes的选择。例如:(checkedListBox1 =限制选择项目的数量为3个项目); (checkedListBox2 =限制只选择2项的项目数); (checkedListBox3 =限制只选择4项的项目数);等.... – 5120bee
让我知道如果这适用于你,我测试它,它在我的情况下工作。 – Niklas