I hope you already had your answer.
I have a solution for mine.
So my requirement is :
I have a custom panel containing a list, each item is a regular string. When I drag an item from a list to a document, at a specific location, I want to insert a merge field at that location. The name of the merge field is the text of the item.
At first it was simple, then I had a problem, as you describe in your question.
About the code
So there is a list, you need to handle mouseDown and mouseMove, do not worry about mouseUp.
In the mouseDown handler, I write a border; if the mouse leaves this border, drag will begin.
Then in listBox_MouseMoveHandler I check the position of the mouse to launch dragdrop. And I have to use DragDropEffects.Copy for the DoDragDrop method.
DoDragDrop((sender as ListControl).SelectedValue, DragDropEffects.Copy);
With this option, SelectedValue will be inserted into the drag position and after setting it will also be selected.
Then I just check if the selection is selected, and replace the selected text with the merge field. Of course, I dropped the choice to DoDragDrop . And this is the whole trick.
private int _selectedItemIndex; private Rectangle dragBoxFromMouseDown; private void CustomizationForListBox(ListBox listBox) { listBox.ItemHeight = 25; listBox.DrawMode = DrawMode.OwnerDrawFixed; listBox.DrawItem += ListBox_DrawItem; listBox.MouseDoubleClick += listBox_MouseDoubleClick; listBox.MouseMove += listBox_MouseMoveHandler; listBox.MouseUp += listBox_MouseUp; listBox.MouseDown += (sender, e) => {
// Replace the selected text with a merge field MergeFieldHelper.InsertSingleMergeField(mergeFieldInfos[_selectedItemIndex].Name); } } } } }