把一个listbox的数据放另一个listbox要如何写程序 把一个listbox的数据放另一个listbox要如何写程序 有两个listbox,listbox1,listbox2 要实现功能 1,listbox1,listbox2 可多选 2,listbox1多选点向右箭头的按钮,可以把listbox1选中的数据放listbox2 中,并可实现全选,反选 3,listbox2多选点向左箭头的按钮,可以把listbox2返回到listbox1 中 没用过这个控件,献丑了,请懂道的给指个道,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 按钮事件中写listBox项的添加删除事件listBox2.Items.Add(listBox1.SelectedItem.ToString());listBox1.Items.Remove(listBox1.SelectedItem); private void right_Click(object sender, EventArgs e) { if (this.listbox1.SelectedItem == null) return; this.listbox2.Items.Add(this.listbox1.SelectedItem.ToString()); this.listbox1.Items.Remove(this.listbox1.SelectedItem); } 1楼和2楼的都是对的勒先在目标控件里添加选中的item,然后选择的控件里移除item. 反选和选过去一样的勒,顺序倒过来了而已。全选的话,用foreach勒,添加到右边、 string listBox1 = this.ListBox1.SelectedItem.Text; this.ListBox2.Items.Add(listBox1); this.ListBox1.Items.Remove(listBox1); <asp:ListBox ID="lst_left" runat="server" SelectionMode="Multiple" Height="203px" Width="130px"></asp:ListBox> <asp:ListBox ID="lst_center" runat="server" SelectionMode="Multiple" Height="203px" Width="130px"></asp:ListBox> <input type="button" id="btn_leftToCenter" value="右移" onclick="MoveOption(document.getElementById('lst_left'),document.getElementById('lst_center'))" /> <input type="button" id="btn_centerToLeft" value="左移" onclick="MoveOption(document.getElementById('lst_center'),document.getElementById('lst_left'))" />function MoveOption(fromSel,toSel){ var fromOp=fromSel.options; var toOp=toSel.options; var selectedFlag=false; for(var i=0;i<fromOp.length;i++) { if(fromOp[i].selected) { selectedFlag=true; var selectedOp=document.createElement("option"); selectedOp.text=fromOp[i].text; selectedOp.value=fromOp[i].value; toSelLength=toOp.length; toSel.options.add(selectedOp,toSelLength); fromSel.options.remove(i); i--; } } if(!selectedFlag) { alert("请选择一项!"); return; }} 寻好点的菜单控件 使用string.remove()方法带来的问题,怎么解决? ff获取event 大家给点意见 水晶报表工具栏的问题 如何取出Cache中的项?? 菜鸟问题:数据库查询再插入,帮我看看,谢谢,在线等 DataGrid问题 为什么记录写不进服务器上的SQL数据库。 dropdownlist如何添加较多的数据 ASP.NET两个字段循环添加的问题 在线等。各位帮我看看吧!感激不尽!关于Server.MapPath()获取物理路径的问题 !!!
listBox2.Items.Add(listBox1.SelectedItem.ToString());
listBox1.Items.Remove(listBox1.SelectedItem);
private void right_Click(object sender, EventArgs e)
{
if (this.listbox1.SelectedItem == null) return;
this.listbox2.Items.Add(this.listbox1.SelectedItem.ToString());
this.listbox1.Items.Remove(this.listbox1.SelectedItem);
}
this.ListBox2.Items.Add(listBox1);
this.ListBox1.Items.Remove(listBox1);
<asp:ListBox ID="lst_left" runat="server" SelectionMode="Multiple" Height="203px"
Width="130px"></asp:ListBox>
<asp:ListBox ID="lst_center" runat="server" SelectionMode="Multiple" Height="203px" Width="130px"></asp:ListBox>
<input type="button" id="btn_leftToCenter" value="右移" onclick="MoveOption(document.getElementById('lst_left'),document.getElementById('lst_center'))" />
<input type="button" id="btn_centerToLeft" value="左移" onclick="MoveOption(document.getElementById('lst_center'),document.getElementById('lst_left'))" />function MoveOption(fromSel,toSel)
{
var fromOp=fromSel.options;
var toOp=toSel.options;
var selectedFlag=false;
for(var i=0;i<fromOp.length;i++)
{
if(fromOp[i].selected)
{
selectedFlag=true;
var selectedOp=document.createElement("option");
selectedOp.text=fromOp[i].text;
selectedOp.value=fromOp[i].value;
toSelLength=toOp.length;
toSel.options.add(selectedOp,toSelLength);
fromSel.options.remove(i);
i--;
}
}
if(!selectedFlag)
{
alert("请选择一项!");
return;
}
}