listbox中选中的图片在hwindowcontrol中显示的时候,该怎么删除选中项,为什么我直接删除会报错
看提示是数组索引越界了。这行下断点看看hv_file的大小和selectedindex的值
多选的处理:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string str = "";
foreach( int i in listBox1.SelectedIndices)
{
str += i + "\n"; //这里不能直接删,直接删除后索引会有变化,这里统计都有哪些选择项,循环结束后批量删除。
}
textBox1.Text = str;
}
试一下这个
private void button1_Click(object sender, EventArgs e)
{
List<object> list = new List<object>();
foreach (int i in listBox1.SelectedIndices)
{
list.Add(listBox1.Items[i]);
}
foreach (object i in list)
{
listBox1.Items.Remove(i);
}
}