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);
}
}