Soul Reaver
Soul Reaver

Reputation: 2092

Copy object using Clipboard and paste it as object or text

I want to copy object ( List ) to clipboard and use it in my application and outside of it. In my application, I want to be able to "paste" data without any additional operation. Outside I need CSV data.

I tried to achieve it by using DataObject. I can convert this list to formatted string - so i think it's easy to get CSV. I stored random string in DataObject, (just for test). The problem is storing List object in Clipboard. DataObject contains specific type ( checked using DataObject.GetFormats() ), but when i try to get this object from clipboard, I get null.

I've found this, while it solves my problem, I need to serialize/deserialize.

Is there any way to store and retrieve object the normal way ?

Upvotes: 2

Views: 3901

Answers (1)

Reza ArabQaeni
Reza ArabQaeni

Reputation: 4907

Clipboard.SetDataObject(list);
var deslist = Clipboard.GetDataObject().GetData(list.GetType());

Upvotes: 1

Related Questions