This project is read-only.

Allow Creation of a DataObject for Drag & Drop


I have a problem with SectionContainerControl.DoDragDropOperation. In this method, sectionToDrag.GetDragObjects() is called, the result is passed to Control.DoDragDrop.
Since the return value is of type object[], it will inside DoDragDrop be cast to a userdefined datatype contained in an OLE DataObject.
I need the possibility to add text to this DataObject; in general it should be possible to add arbitrary data to it. One reason for this is, that the data might be dragged to a different application.

My workaround was, to add a template method to SectionContainerControl:

    protected virtual object GetDragObjectFromDragObjects(object[] dataArray)
        return dataArray;



Before calling Control.DoDragDrop I allow for conversion of the default data object

    object dragObject = GetDragObjectFromDragObjects(data);

if (DoDragDrop(dragObject, DragDropEffects.Copy | DragDropEffects.Move) == DragDropEffects.None)


In the overridden method I do something like

    protected override object GetDragObjectFromDragObjects(object[] dataArray)
        object data = base.GetDragObjectFromDragObjects(dataArray);
        DataObject dataObject = new DataObject(data);
        string myText = "myText";
        dataObject.SetData(DataFormats.Text, myText);
        return dataObject;


Cleaner (but of course much more intrusive) would be to modify the return type of GetDragObjects().