.NET 程序花园

光说不练那是花把式,照不住。光练不说那是在自我陶醉,心要有数。 ~^_^~

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  1. 单项移动
 1            ListItem[] myListItemArray1  = new ListItem[ListBox1.Items.Count];
 2            ListItem[] myListItemArray2  = new ListItem[ListBox2.Items.Count];
 3            ListBox1.Items.CopyTo(myListItemArray1, 0);
 4            
 5            ListBox2.Items.CopyTo(myListItemArray2,0);     
 6            ArrayList list1 = new ArrayList();
 7           ArrayList list2 = new ArrayList();
 8            for(int i=0;i<myListItemArray1.Length;i++)
 9            {
10                list1.Add(myListItemArray1[i]);
11            }

12            
13            for(int i=0;i<myListItemArray2.Length;i++)
14            {
15                list2.Add(myListItemArray2[i]);
16            }

17
18            if(this.ListBox1.Items.Count>0  )
19            {
20                if(!list2.Contains(this.ListBox1.SelectedItem))
21                {                            
22                    this.ListBox2.Items.Add(this.ListBox1.SelectedItem);
23                    this.ListBox1.Items.Remove(this.ListBox1.SelectedItem);
24                    this.ListBox1.ClearSelection();
25                    this.ListBox2.ClearSelection();
26                    this.ListBox2.SelectedIndex=0;
27                    this.ListBox1.SelectedIndex=0;
28                }

29            }
    
30            else
31            {
32                    return ;
33            }

2 .全移动
ListItem[] myListItemArray1  = new ListItem[ListBox1.Items.Count];
            ListItem[] myListItemArray2  
= new ListItem[ListBox2.Items.Count];

            ListBox1.Items.CopyTo(myListItemArray1, 
0);
            
            ListBox2.Items.CopyTo(myListItemArray2,
0);     
        ArrayList list1 
= new ArrayList();
        ArrayList list2 
= new ArrayList();            
            
for(int i=0;i<myListItemArray1.Length;i++)
            
{
                list1.Add(myListItemArray1[i]);
            }

            
            
for(int i=0;i<myListItemArray2.Length;i++)
            
{
                list2.Add(myListItemArray2[i]);
            }



            
if(list2.Count>0)
            
{
                 
                
for (int i=0; i<list1.Count;i++)
                
{
                    
if(list2.Contains(list1[i]))
                        
continue;
                    
else
                        list2.Add(list1[i]);
                }

                ListBox1.Items.Clear();
                
this.ListBox2.Items.Clear();
                
this.ListBox2.DataSource = list2 ;
                
this.ListBox2.DataBind();    
                    
            }

            
else
            
{
                
for(int u =0;u<myListItemArray1.Length;u++)
                
{
                    
this.ListBox2.Items.Add(myListItemArray1[u]);
                }

                ListBox1.Items.Clear();
            
            }

            
            
this.ListBox2.SelectedIndex=0;

posted on 2007-04-29 14:35  北回归线  阅读(270)  评论(0编辑  收藏  举报