If you have a WinForm application with a ListBox displaying the drawing file paths and you wish to perform a drag and drop of those ListBox items into AutoCAD, then here is a code snippet to ensure that AutoCAD takes appropriate action on those dropped items.
Step 1)
Handle the MouseMove event of the ListBox. As an example, if the ListBox is named "fileNamesListBox" then you would add the event handler as :
this.fileNamesListBox.MouseMove
+= new System.Windows.Forms.MouseEventHandler(this.fileNamesListBox_MouseMove);
Step 2)
Inside the MouseMove event handler of the ListBox, call the DoDragDrop with the appropriate parameters. In this case the list of drawing file paths that were selected in the ListBox.
private void fileNamesListBox_MouseMove(object sender, MouseEventArgs e)
{
if (System.Windows.Forms.Control.MouseButtons
== System.Windows.Forms.MouseButtons.Left)
{
System.Windows.Forms.DataObject myDataObject
= new System.Windows.Forms.DataObject();
System.Collections.Specialized.StringCollection dwgFileNames
= new System.Collections.Specialized.StringCollection();
foreach (Object so in fileNamesListBox.SelectedItems)
{
dwgFileNames.Add(so.ToString());
}
if (dwgFileNames.Count > 0)
{
myDataObject.SetFileDropList(dwgFileNames);
System.Windows.Forms.DragDropEffects dropEffect
= fileNamesListBox.DoDragDrop
(
myDataObject,
System.Windows.Forms.DragDropEffects.Copy
);
}
}
}