Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
That darn Clipboard
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01134782
Message ID:
01135004
Views:
20
This message has been marked as the solution to the initial question of the thread.
>I am having some issues with my clipboard. The following code is almost a straight copy from the docs.
>
>
>Clipboard.SetData("Class1Format", new Class1("42"));
>if (Clipboard.ContainsData("Class1Format"))
>{
>	Class1 o = Clipboard.GetData("Class1Format") as Class1;
>	// is is null here so the line below will throw an exception
>	MessageBox.Show(o.MyMethod());
>}
>else
>{
>	MessageBox.Show("Ain't nothing there!!");
>}
>
>
>I think the instance of Class1 is placed in the clipboard successfully but there are some issues retreiving it. I have also tried the "old" way:
>
>Clipboard.SetDataObject(new Class1("42"));
>Class1 o = Clipboard.GetDataObject() as Class1;
>// o is null!!
>MessageBox.Show(o.MyMethod());
>
>
>I got a feeling is is something very simple that I am missing.
>
>TIA,
>Einar

It is amazing what information is in the M$ docs :) Here is what I found:

An object must be serializable for it to be put on the Clipboard. If you pass a non-serializable object to a Clipboard method, the method will fail without throwing an exception.


So adding [Serializable] to my class did the trick.
Semper ubi sub ubi.
Previous
Reply
Map
View

Click here to load this message in the networking platform