分享

在C#中实现两个listbox的项移动(winform)

 昵称10504424 2013-02-20
      1. using System;  
      2. using System.Collections.Generic;  
      3. using System.ComponentModel;  
      4. using System.Data;  
      5. using System.Drawing;  
      6. using System.Linq;  
      7. using System.Text;  
      8. using System.Windows.Forms;  
      9.   
      10. namespace arblistbox  
      11. {  
      12.     public partial class Form1 : Form  
      13.     {  
      14.         public Form1()  
      15.         {  
      16.             InitializeComponent();  
      17.   
      18.         }  
      19.   
      20.         private void button1_Click(object sender, EventArgs e)  
      21.         {  
      22.             if (listBox1.Items.Count == 0)  
      23.                 return;  
      24.             if (listBox1.SelectedItem == null)  
      25.                 return;  
      26.             listBox2.Items.Add(listBox1.SelectedItem);  
      27.             listBox1.Items.Remove(listBox1.SelectedItem);  
      28.               
      29.   
      30.         }  
      31.   
      32.         private void button2_Click(object sender, EventArgs e)  
      33.         {  
      34.             if (listBox1.Items.Count == 0)  
      35.                 return;  
      36.             for(int i=0;i<listBox1.Items.Count;i++)  
      37.             {  
      38.                listBox2.Items.Add(listBox1.Items[i]);  
      39.             }  
      40.   
      41.             for (int j = 0; j< listBox2.Items.Count;j++)  
      42.             {  
      43.                 listBox1.Items.Remove(listBox2.Items[j]);  
      44.             }  
      45.   
      46.         }  
      47.   
      48.         private void button3_Click(object sender, EventArgs e)  
      49.         {  
      50.             if (listBox2.Items.Count == 0)  
      51.                 return;  
      52.             if (listBox2.SelectedItem == null)  
      53.                 return;  
      54.             listBox1.Items.Add(listBox2.SelectedItem);  
      55.             listBox2.Items.Remove(listBox2.SelectedItem);  
      56.   
      57.         }  
      58.   
      59.         private void button4_Click(object sender, EventArgs e)  
      60.         {  
      61.             if (listBox2.Items.Count == 0)  
      62.                 return;  
      63.             for (int i = 0; i < listBox2.Items.Count; i++)  
      64.             {  
      65.                 listBox1.Items.Add(listBox2.Items[i]);  
      66.             }  
      67.   
      68.             for (int j = 0; j < listBox1.Items.Count; j++)  
      69.             {  
      70.                 listBox2.Items.Remove(listBox1.Items[j]);  
      71.             }  
      72.   
      73.         }  
      74.     }  
      75. }  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多