ListBox设置为MultiExtended,界面中有一个按钮允许删除选择的Item,但我总是不能一次性删除所选的全部,我的实现代码如下:private void btnDel_Click(object sender, System.EventArgs e)
{
for(int count = 0;count < this.lstSampleFields.SelectedItems.Count;count++)
{
this.lstSampleFields.Items.Remove(this.lstSampleFields.Items[count]);
}
this.lstSampleFields.Refresh();
}不知道哪里出了问题,请帮帮忙吧~~~谢谢!
{
for(int count = 0;count < this.lstSampleFields.SelectedItems.Count;count++)
{
this.lstSampleFields.Items.Remove(this.lstSampleFields.Items[count]);
}
this.lstSampleFields.Refresh();
}不知道哪里出了问题,请帮帮忙吧~~~谢谢!
{
ListBox1.Items.Clear();//.Remove(ListBox1.Items);
}
{
if(this.ListBox1.Items[i].Selected)
this.ListBox1.Items.Remove(this.ListBox1.Items[i]);
}
呵呵。
呃对哦,索引不一样呃
你代码里的this.ListBox1.Items[i].Selected,貌似么有这个属性哦?点不出来
敲进去编译报错说Selected未定义按照这个解决思路分析,即使用IndexOf得到真实的index,如果用循环,删掉第一个后剩下的选项索引也会随之改变,还是不行。难道一定要提取选项的值来进行操作?
{
while (this.listBox1.SelectedItems.Count > 0)
this.listBox1.Items.Remove(this.listBox1.SelectedItems[0]);
}