I have a c# project using version 4.0 of the .net framework, and running on VS 2010. I have created a tree view populated with some extended tree nodes. I want the user to be able to copy, cut, and paste these nodes to the clipboard via a context menu or keyboard shortcuts (and not just drag-drop).
The code runs fine when copying, but when I try to paste these nodes it throws this error: Unable to cast object of type 'System.IO.MemoryStream' to type 'Namespace Path.TreeNodeEx'.
Here's my cut/copy/paste methods.
public void Copy()
{
Clipboard.SetData("Tree Node Ex", CurrentTreeNode.Clone());
}
public void Paste()
{
CurrentTreeNode.Nodes.Add((TreeNodeEx)Clipboard.GetData("Tree Node Ex"));
}
I suspect the problem is something to do with serialization, but I've tried implement the ISeralizable Interface and the [Serializable] attribute to no avail.
Any suggestions?