日期:2014-05-18  浏览次数:20921 次

如何实现两个listbox拖动操作,如何实现?
如何实现两个listbox里面的Item拖动操作,如何实现?

可以把第一个listbox的item拖到另一个listbox里面

不要按钮操作,直接拖

------解决方案--------------------
up!
------解决方案--------------------
up!
------解决方案--------------------
C# code

//参考,2个listbox都绑定到下面的事件处理函数

private bool isLeftMouseButtonDown = false;

        private void listBox_DragDrop(object sender, DragEventArgs e)
        {
            ListBox destListBox = sender as ListBox;
            if (e.Data.GetDataPresent(typeof(ListBox)))
            {
                ListBox srcListBox = e.Data.GetData(typeof(ListBox)) as ListBox;
                destListBox.Items.Add(srcListBox.SelectedItem);
                srcListBox.Items.Remove(srcListBox.SelectedItem);
            }
        }

        private void listBox_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
        }

        private void listBox_MouseDown(object sender, MouseEventArgs e)
        {
            isLeftMouseButtonDown = true;
        }

        private void listBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (isLeftMouseButtonDown)
            {
                ListBox lb = sender as ListBox;
                if (lb.SelectedItem != null)
                {
                    lb.DoDragDrop(lb, DragDropEffects.Move);
                }
            }
        }

        private void listBox_MouseUp(object sender, MouseEventArgs e)
        {
            isLeftMouseButtonDown = false;
        }

------解决方案--------------------
4楼的就可以。

不过:首先:使你的第二个listbox的AllowDrop属性设为真,使其可以接受拖放的数据。


------解决方案--------------------
向四楼学习.
------解决方案--------------------
isLeftMouseButtonDown 是什么啊!?
------解决方案--------------------
mark