#696 – A Drop Target Can Receive Data from Other Applications

When you designate an element in your user interface as a drop target for a drag-and-drop operation, it can receive data that is dragged from other elements in your application, provided that those elements initiate the drag-and-drop operation.  But a drop target element in your application can also serve as a target for a drag source in another application.

You can set the AllowDrop property to true for an element and then add code for the element’s Drop event, where you call IDataObject.GetData to get the dragged data.

In the example below, we’ve made a ListBox the drop target.  We can then drag some text onto it from Microsoft Word.

        private void lbDrop(object sender, DragEventArgs e)
            string draggedText = (string)e.Data.GetData(DataFormats.StringFormat);

            ListBox lbox = e.Source as ListBox;


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

One Response to #696 – A Drop Target Can Receive Data from Other Applications

  1. Pingback: Dew Drop – November 23, 2012 (#1,448) | Alvin Ashcraft's Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: