Clipboard and custom data

S

Steffen

hi,

there's some very strange with the clipboard (I'm using .NET 2.0). I
tried to set an object (type is inherited from TreeNode) to the
clipboard. This works fine but when I want to retrieve this object from
clipboard it doesn't work. It's strange because the GetDataPresent
methode returns "true" when I ask wether the requested type of object
is present at the clipboard. However getting the object returns "null".
Here's some code of my app:

// copy to clipboard
TreeNodeEx copy = (TreeNodeEx)treeCards.SelectedNode.Clone();
DataObject data = new DataObject();
data.SetData("Test", copy);
Clipboard.SetDataObject(data);

// paste from clipboard
TreeNodeEx t = Clipboard.GetDataObject().GetData("Test") as TreeNodeEx;

// type of the object
[Serializable]
class TreeNodeEx : TreeNode
{
[...]
}

Why doesn't this work?
Thanks for any help

Steffen
 
M

Michael Phillips, Jr.

data.SetData("Test", copy);

"Test" is not a registered clipboard format.

If you want to register a custom clipboard format called "Test", you may do
so but you are responsible for implementing an IDataObject interface that
will support this custom format.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top