ListBox选中多行添加 两个listBox 选中第一个listBox中的行,点击添加,然后添加到第二个ListBox中 同时第一个ListBox中选中的行要删除,怎么解决。希望知道的人顶一下! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先你取到第一个listbox被选中的值,将它Add()到第二个listbox 然后最后将第一个listbox被选中的值Remove()一下 http://topic.csdn.net/u/20100924/10/edaecd9a-a9c5-4e44-9c7a-1208588d89b4.html 怎么没有人回答呀!这个问题很难吗!添加的代码: for (int i = 0; i < listBox1.Items.Count; i++) { if (listBox1.Items[i].Selected) { listBox2.Items.Add(listBox1.Items[i].Text); } }删除的代码: for (int i = listBox1.Items.Count - 1; i > -1; i--) { if (listBox1.Items[i].Selected) { listBox1.Items.Remove(listBox1.Items[i]); } } 楼主在5楼做的很对!不过,若ListBox1是单选的话,可以不用循环,如: ListBox2.Items.Add(ListBox1.SelectedItem); ListBox1.Items.Remove(ListBox1.SelectedItem); ListBox1.SelectedIndex = -1; ListBox2.SelectedIndex = -1; 哦 我犯了一个很低级的错误 我把value值都写成一样的了,这就是问题出在的地方! 电子商务数据库建表的问题 网站美工的素材一般在哪找?程序员如果开发网站,想找套一些现成的网站模版哪比较多? DataTable删除行的问题 用户控件 不执行 js 函数 视频点播的问题。大伙进来看看。播放不连续的问题 数据库多用户使用和连接未关闭的异常问题? 光标问题,在线等待! 怎么把值赋给radiobottom ? 救命啊~~~ asp.net怎样连接postgresql ………………分不多了:html调用后台方法……………… 急救!关于asp中读cookie 和asp.net中GridView以cookie当查询条件的疑问
添加的代码:
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (listBox1.Items[i].Selected)
{
listBox2.Items.Add(listBox1.Items[i].Text); }
}
删除的代码:
for (int i = listBox1.Items.Count - 1; i > -1; i--)
{
if (listBox1.Items[i].Selected)
{
listBox1.Items.Remove(listBox1.Items[i]);
}
}
不过,若ListBox1是单选的话,可以不用循环,如:
ListBox2.Items.Add(ListBox1.SelectedItem);
ListBox1.Items.Remove(ListBox1.SelectedItem); ListBox1.SelectedIndex = -1;
ListBox2.SelectedIndex = -1;