listbox

  1.  protected void Page_Load(object sender, EventArgs e)   
  2.     {   
  3.         if (!Page.IsPostBack)   
  4.         {   
  5.             for (int i = 0; i < 10; i++)   
  6.             {   
  7.                 this.lbxSource.Items.Add(new ListItem("★"+i, i.ToString()));   
  8.             }   
  9.         }   
  10.            
  11.     }   
  12.   
  13.     protected void listBoxOperate_OnCommand(object sender,CommandEventArgs e)   
  14.     {   
  15.         ArrayList arrTo = new ArrayList();   
  16.         switch (e.CommandName)   
  17.         {   
  18.             case "ToRight":   
  19.                 if (this.lbxSource.SelectedIndex == -1)   
  20.                 {   
  21.                     break;   
  22.                 }   
  23.                 else  
  24.                 {   
  25.                     foreach(ListItem item in lbxSource.Items)   
  26.                     {   
  27.                         if(item.Selected)   
  28.                         {   
  29.                             arrTo.Add(item);   
  30.                         }   
  31.                     }   
  32.   
  33.                     foreach (ListItem item in arrTo)   
  34.                     {   
  35.                         this.lbxTo.Items.Add(item);   
  36.                         this.lbxSource.Items.Remove(item);   
  37.                     }   
  38.                        
  39.                     break;   
  40.                 }   
  41.                    
  42.             case "AllToRight":   
  43.                 if (this.lbxSource.Items.Count > 0)   
  44.                 {   
  45.                     foreach (ListItem item in lbxSource.Items)   
  46.                     {   
  47.                         this.lbxTo.Items.Add(item);   
  48.                     }   
  49.                     this.lbxSource.Items.Clear();   
  50.                     break;   
  51.                 }   
  52.                 else  
  53.                 {   
  54.                     break;   
  55.                 }   
  56.             case "ToLeft":   
  57.                 if(this.lbxTo.SelectedIndex == -1)   
  58.                 {   
  59.                     break;   
  60.                 }   
  61.                 else  
  62.                 {   
  63.                     foreach (ListItem item in lbxTo.Items)   
  64.                     {   
  65.                         if (item.Selected)   
  66.                         {   
  67.                             arrTo.Add(item);   
  68.                         }   
  69.                     }   
  70.   
  71.                     foreach (ListItem item in arrTo)   
  72.                     {   
  73.                         this.lbxSource.Items.Add(item);   
  74.                         this.lbxTo.Items.Remove(item);   
  75.                     }   
  76.                        
  77.                     break;   
  78.                 }   
  79.                 break;   
  80.             case "AllToLeft":   
  81.                 if (this.lbxTo.Items.Count > 0)   
  82.                 {   
  83.                     foreach (ListItem item in lbxTo.Items)   
  84.                     {   
  85.                         this.lbxSource.Items.Add(item);   
  86.                     }   
  87.                     this.lbxTo.Items.Clear();   
  88.                     break;   
  89.                 }   
  90.                 else  
  91.                 {   
  92.                     break;   
  93.                 }   
  94.             case "ToUp":   
  95.                 for (int i = 0; i < lbxTo.Items.Count; i++)   
  96.                 {   
  97.                     if (lbxTo.Items[i].Selected)   
  98.                     {   
  99.                         if (i > 0 && lbxTo.SelectedIndex > -1)   
  100.                         {   
  101.                             ListItem item = lbxTo.Items[i];   
  102.                             lbxTo.Items.RemoveAt(i);   
  103.                             lbxTo.Items.Insert(i - 1, item);   
  104.                         }   
  105.                     }   
  106.                 }   
  107.                 break;   
  108.             case "ToDown":   
  109.                 for (int i = lbxTo.Items.Count - 1; i > -1; i--)   
  110.                 {   
  111.                     if (lbxTo.Items[i].Selected)   
  112.                     {   
  113.                         ListItem item = lbxTo.Items[i];   
  114.                         if (i < lbxTo.Items.Count - 1)   
  115.                         {   
  116.                             lbxTo.Items.Insert(i + 2, item);   
  117.                             lbxTo.Items.RemoveAt(i);   
  118.                         }   
  119.   
  120.                     }   
  121.                 }   
  122.                 break;   
  123.         }   
  124.     }   
  125.   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值