0

I have a simple DragAndDrop sample which should move a string from one ListBox to another. The string gets dropped, but it is not removed from the source even though Move is specified. Where have I gone wrong? Here is the code:

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

        private void button1_Click(object sender, EventArgs e) {
            string[] items = { "Hello", "GoodBye", "World" };
            foreach (string item in items)
                listBox1.Items.Add(item);
        }

        private void listBox2_DragEnter(object sender, DragEventArgs e) {
            if (e.Data.GetDataPresent(typeof(string)))
                e.Effect = DragDropEffects.Move;
            else
                e.Effect = DragDropEffects.None;
        }

        private void listBox2_DragDrop(object sender, DragEventArgs e) {
            listBox2.Items.Add((string)e.Data.GetData(typeof(string)));
        }

        private void listBox1_MouseDown(object sender, MouseEventArgs e) {
            DoDragDrop(listBox1.Items[listBox1.SelectedIndex], DragDropEffects.Move);
        }
    }
2
Contributors
1
Reply
3
Views
9 Years
Discussion Span
Last Post by Despa22
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.