如下就行了:
private void Button1_Click(object sender, System.EventArgs e)
{
foreach(int index in ListBox1.SelectedIndices)
{
ListBox2.Items.Add(ListBox1.Items[index].Text);
ListBox1.Items.RemoveAt(index);
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
foreach(int index in ListBox1.SelectedIndices)
{
ListBox2.Items.Add(ListBox1.Items[index].Text);
ListBox1.Items.RemoveAt(index);
}
}
解决方案 »
- 这三种数据类型建模方式,有区别吗?
- [求助]IE插件,如何自动在新窗口打开iframe内的页面
- comboBox1_SelectedIndexChanged事件中comboBox1.SelectedValue取不到值!
- Linq查询返回的数据转化问题
- 如何实现以下的功能?
- 装配件的几个问题
- 水晶报表的问题! 各位高手请进~~ :)
- 如何让COMBOX下拉列表与数据表的ID列的值对应显示啊?????头疼
- 如何在c#中使用象vb中redim preserve 的语句
- C#读写INI文件的问题
- 求助阿!!!!!!!!!!!!!C#中的BUG
- 如何让一个窗口总在另一个窗口上方?就像word的搜索那样,但不是对话框
这句话是干什么的??还有你应该从后面往前处理~~ 也就是说从n~ 0~~
不然处理到后面会超出边界~
错了~~ 你在foreach里面改变了枚举的元素~
ListBox1.Items[ListBox1.Items.Count-1].Selected=false;
要做什么?
{
//如果没选中左边listBox中的项则出现对话框。
if(listBox1.SelectedIndex==-1)
{
MessageBox.Show("没选中");
}
else
{
//右边的listBox中加入左边listBox的项
listBox2.Items.Add(listBox1.Items[listBox1.SelectedIndex]);
//把左边的项给去掉。
listBox1.Items.Remove(listBox1.Items[listBox1.SelectedIndex]);
}
}
foreach(int index in listBox1.SelectedIndices)
listBox2.Items.Add(listBox1.Items[index].ToString());for(int i=listBox1.SelectedIndices.Count-1;i>=0;i--)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]);
}
我的listbox1中的内容是通过数据库中的一个字段绑定的
ListBox1.DataTextField="name";
ListBox1.DataValueField="name";
我写的if (listbox1.selectedindex!=-1) {
.....
}
明明我选择了其中的一项,但却就是=-1 ,各位大侠,请问为什么,谢谢了?
{listBox2.Items.add(listBox1.Text);
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
请再看我的问题
不好意思,我没说清楚
我的listbox1中的内容是通过数据库中的一个字段绑定的
ListBox1.DataTextField="name";
ListBox1.DataValueField="name";
我写的if (listbox1.selectedindex!=-1) {
ListBox2.Items.Add(new ListItem(ListBox1.SelectedItem.Value));
ListBox1.Items.Remove(ListBox1.SelectedItem.Value);
}
明明我选择了其中的一项,但却就是=-1 ,各位大侠,请问为什么,谢谢了?