Collection was modified; enumeration may not execute error when removing a ListItem from a LIstBox

后端 未结 9 652
抹茶落季
抹茶落季 2020-11-29 12:30

I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add and Remove. When a color or colors is selected in lstAvailableCol

9条回答
  •  一整个雨季
    2020-11-29 12:46

    Maybe this is what you need

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        while(listBox1.SelectedIndex!=-1)
        {
               listBox1.Items.Remove(listBox1.SelectedItem);
        }
    }
    

提交回复
热议问题