日期:2014-05-17 浏览次数:21398 次
选中第五个时,自动取消 private void listBox1_Click(object sender, EventArgs e) { if (listBox1.SelectedItems.Count >4) { for (int i = 0; i < listBox1.SelectedItems.Count; i++) { if (listBox1.SelectedItem != listBox1.SelectedItems[i]) { listBox1.SetSelected(listBox1.SelectedIndex,false); return; } } } }
------解决方案--------------------
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 4)
{
for (int i = 0; i < listBox1.SelectedItems.Count; i++)
{
if (listBox1.SelectedItem != listBox1.SelectedItems[i])
{
listBox1.SetSelected(listBox1.SelectedIndex, false);
return;
}
}
}
}
------解决方案--------------------
还没有弄好吗?你可以这样子滴:
void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listBox1.SelectedItems.Count > 4)
{
this.listBox1.SelectedItems.Remove(this.listBox1.SelectedItem);
}
}