把一个listbox的数据放另一个listbox要如何写程序 有两个listbox,listbox1,listbox2
 要实现功能
 1,listbox1,listbox2 可多选
 2,listbox1多选点向右箭头的按钮,可以把listbox1选中的数据放listbox2 中,并可实现全选,反选
 3,listbox2多选点向左箭头的按钮,可以把listbox2返回到listbox1 中 没用过这个控件,献丑了,请懂道的给指个道,谢谢!

解决方案 »

  1.   

    按钮事件中写listBox项的添加删除事件
    listBox2.Items.Add(listBox1.SelectedItem.ToString());
    listBox1.Items.Remove(listBox1.SelectedItem);
      

  2.   


      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);
            }
      

  3.   

    1楼和2楼的都是对的勒先在目标控件里添加选中的item,然后选择的控件里移除item.
      

  4.   

    反选和选过去一样的勒,顺序倒过来了而已。全选的话,用foreach勒,添加到右边、
      

  5.   

    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;
      }
    }