C#如何将listBox1里面的内容移动到listBox2里面 ,net/webform

//双击">>"按钮,产生事件如下:
           
protected void RemoveAll(object sender, EventArgs e)
           
{  
  this.ListBox2.Items.Clear();//首先清除listBox2中的内容  
               
  for(int i = 0; i < ListBox1.Items.Count; i ++)  
               
  {     
                   
  ListBox2.Items.Add(ListBox1.Items[i]);//将listBox1中的元素添加到listBox2中;  
               
  }  
               
ListBox1.Items.Clear();//首先清除listBox1中的内容}"<<"这个按钮事件和上面类似;


//双击">"按钮,产生如下事件:
               
protected void Remove(object sender, EventArgs e)
               
{  
                   
  for(int i = 0; i < ListBox1.Items.Count; i ++)  
                   
  {      
                       
    if(ListBox1.Items[i].Selected)//如果该项被选择;     
                       
    {         
                           
    this.ListBox2.Items.Add(ListBox1.Items[i]);         
                           
    this.ListBox1.Items.Remove(ListBox1.Items[i]);      
                       
    }  
                   
  }
               
}//"<"按钮事件类似~~
posted @ 2015-10-28 17:10  praiselee  阅读(1165)  评论(0)    收藏  举报