关于两个ListBox的传值与删除item问题
目的就是把选种listBox1的Items插入到listbox2,并删除选择listBox1的items
listBox1可以多选.
以下代码执行有错误,应该怎样改进才能实现上述功能呢?
当foreach执行第二编就出错了.
private void Button1_Click(object sender, System.EventArgs e)
{
foreach( ListItem ls in this.ListBox1.Items )
{
if( ls.Selected )
{
ListItem lstItem = new ListItem();
lstItem.Text = ls.Text;
lstItem.Value = ls.Value;
this.ListBox2.Items.Add( lstItem );
this.ListBox1.Items.Remove( ls );
//this.ListBox2.Items.
}
}
}