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

Re: Clipboard and custom data by Michael

Michael
Tue Jun 13 13:58:03 CDT 2006

> 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.


"Steffen" <steffen_home_92@hotmail.com> wrote in message
news:1149836819.778285.271240@c74g2000cwc.googlegroups.com...
> 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
>