| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 488 人关注过本帖
标题:求Listbox的操作!!
只看楼主 加入收藏
qweeam
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-3-26
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
求Listbox的操作!!
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EX2_123
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Close();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            int i;
            for (i = listBox1.Items.Count - 1; i >= 0; i--)
            {
                listBox2.Items.Add(listBox1.Items[i]);
                listBox1.Items.RemoveAt(i);
            }

            ShowBtnEn();

        }
        private void button3_Click(object sender, EventArgs e)
        {
            int i;
            for (i = listBox2.Items.Count - 1; i >= 0; i--)
                if (listBox2.GetSelected(i))
                {
                    listBox1.Items.Add(listBox2.Items[i]);
                    listBox2.Items.RemoveAt(i);

                }
            ShowBtnEn();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            int i;
            for (i = listBox1.Items.Count - 1; i >= 0; i--)
                if (listBox1.GetSelected(i))
                {
                    listBox2.Items.Add(listBox1.Items[i]);
                    listBox1.Items.RemoveAt(i);
                }
            ShowBtnEn();



        }

        private void button6_Click(object sender, EventArgs e)
        {

        }

     
        void ShowBtnEn()
        {

            if (listBox1.Items.Count != 0)
            {
                if (listBox2.Items.Count == 0)
                {
                    button3.Enabled = false;
                    button4.Enabled = false;
                    button1.Enabled = true;
                    button2.Enabled = true;
                }
                else
                {
                    button3.Enabled = true;
                    button4.Enabled = true;
                    button1.Enabled = true;
                    button2.Enabled = true;
                }
            }
            else
            {
               
                    button1.Enabled = false;
                    button2.Enabled = false;
                    button3.Enabled = true;
                    button4.Enabled = true;
               
            }



        }

        private void button4_Click(object sender, EventArgs e)
        {
            int i;
            for (i = listBox2.Items.Count - 1; i >= 0; i--)
            {
                listBox1.Items.Add(listBox2.Items[i]);
                listBox2.Items.RemoveAt(i);
            }
            ShowBtnEn();

        }

        private void listBox1_DragLeave(object sender, EventArgs e)
        {
        }

        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
        

        }

        private void button5_Click(object sender, EventArgs e)
        {   int i;
            string s1;
            for (i = listBox1.Items.Count; i > 0; i--)
            {
            }

           
        }

    }
}
         

这个是我编的程序。
剩下的作业要求
1.是通过↑↓按钮调整items的位置
2.拖曳直接在两个listbox间移动items


做好的大神请回帖 谢谢!~
搜索更多相关主题的帖子: class private public 
2011-03-29 22:36
zhp223
Rank: 5Rank: 5
等 级:职业侠客
帖 子:99
专家分:362
注 册:2010-3-21
收藏
得分:10 
拖曳请参考:http://blog.

日有所思,夜有所梦
2011-03-30 12:03
快速回复:求Listbox的操作!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.035993 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved