I try to implement a drag-drop between a listbox and a richtextbox. but I get the data duplicate!

The used implementation is the following:

Code Snippet

public Form1()
//1.- Create a handler for Drag and Drop in the receptor control
richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop);
richTextBox1.AllowDrop = true;
richTextBox1.EnableAutoDragDrop = true;
private void listBox1_MouseDown(object sender, MouseEventArgs e)
string id = listBox1.Items[listBox1.IndexFromPoint(e.Location)].ToString();
//3.- Use the methode DoDragDrop of the receptor control to pass the data to drag
listBox1.DoDragDrop(id, DragDropEffects.Copy);

void richTextBox1_DragDrop(object sender, DragEventArgs e)
//4.- Get the data using the GetData in receptor
string id = (string)e.Data.GetData(typeof(string));
richTextBox1.Text = id;

If the EnabeAutoDragDrop = false, then I can not drag and drop over the richtextbox. (Drag nd Drop is not raised.
allowDrop has not influence.
if I comment the data in _DragDrop event then the data are not duplicate, then the question is. Exist the possibility to use the _DragDrop Event without get the data duplicate

I Use NET 2.0 in Visual Studio 2005, Windows VISTA

Re: Windows Forms General richtextbox duplicate drag and drop result


You'll need to write the DragEnter event. Then you can turn EnableAutoDragDrop off.

Re: Windows Forms General richtextbox duplicate drag and drop result


Thanks for your response,
I didní»t understood the use of DragDrop Event. The dragDrop event is linked with EnableAutoDragDrop, but EnableAutoDragDrop automatic write the dragged values in the richteditBox. The use of the event is only in the case that you need a further data transformation. (example to change the back color in response to a drop event)

The DragEnter is controller by AllowDrop.