假设我有一个按"1“、"2”、"3“、"4”和"5“顺序排列的CheckedListBox,我想通过选择"2”然后按住shift键并选择"4“来选择"2”、"3“和"4”。有没有什么内置的方法可以通过CheckedListBox控件来实现这一点?我发现了一篇关于如何使用SelectedIndexChanged事件来接近此行为的文章,但是尽管它检查多个项,但它不会将它们显示为选中状态。
http://www.windowsdevelop.com/windows-forms-general/multiple-selection-checkbox-53049.shtml
如果有一个我可以使用的替代控件,那么我也会这么做的。
发布于 2010-10-01 02:15:56
可能还有一种更简单的替代方法,但您可以使用ListView,将CheckBoxes设置为true,将HeaderStyle设置为None,将View设置为List。
更正:
应该已将View设置为Details。
发布于 2013-02-23 08:11:18
不支持多选,但我是通过搜索找到CheckedItems的。
选中项是指已标记的项,选中项是指已选中的项。
因此,如果希望项具有选中的复选框,请使用.CheckedItems属性而不是.SelectedItems。
发布于 2012-02-08 22:26:15
对于今天的多重检查,我想出了这个:
List<int> listBox2_selectionhistory = new List<int>();
private void checkedListBox2_SelectedIndexChanged(object sender, EventArgs e)
{
int actualcount = listBox2_selectionhistory.Count;
if (actualcount == 1)
{
if (Control.ModifierKeys == Keys.Shift)
{
int lastindex = listBox2_selectionhistory[0];
int currentindex = checkedListBox2.SelectedIndex;
int upper = Math.Max(lastindex, currentindex) ;
int lower = Math.Min(lastindex, currentindex);
for (int i = lower; i < upper; i++)
{
checkedListBox2.SetItemCheckState(i, CheckState.Checked);
}
}
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
else
{
listBox2_selectionhistory.Clear();
listBox2_selectionhistory.Add(checkedListBox2.SelectedIndex);
}
}据我所知,checkedlistboxes的SelectionMode只能是1或none,这意味着你永远不能让应用一次选择超过1个(我也使用这个行为来简化我的checkedlistboxes代码)
https://stackoverflow.com/questions/3833482
复制相似问题