I have a user defined control which I'm using to display data. I'd like
to be able to "cut" and "paste" the entire control by placing it on the
clipboard so that other parts of my application can access it. (I know
the control won't be accessible outside my application.) This is my code:
ctrl.Parent= null;
DataObject data= new DataObject( "MyControl", ctrl );
Clipboard.SetDataObject( data, false );
IDataObject i= Clipboard.GetDataObject(); // Make sure it worked
The last line is just for testing purposes. I stepped through these
lines of code using Visual Studio, then performed a "QuickWatch".
Evaluating
i.GetDataPresent( "MyControl" )
returns true, but evaluating
i.GetData( "MyControl" )
returns null. By comparison, when I evaluate
data.GetData( "MyControl" )
I get a full description of the Control I was trying to add--which makes
me think I did something wrong adding the DataObject to the clipboard?
Or maybe you just can't put Controls on the clipboard?
By the way, I was able to use drag-n-drop without a problem--this worked
fine:
DataObject data= new DataObject( "MyControl", Parent );
DoDragDrop( data, DragDropEffects.Move );
Thanks for any help.