Placing Multiple Formats in the Clipboard

G

Guest

I'm new to using the clipboard so forgive me if this is a very dumb question.
All the documentation recommends puting as many formats in to the clipboard
as you can so that other applications will be able to paste what was copied.

I have code like this in a copy method:

DataFormats.Format fmtCdsCell = DataFormats.GetFormat ("MyDataFormat");

Build Format...

Clipboard.SetData(fmtCdsCell.Name, object);

Build a plain text representation...

Clipboard.SetText(strText);


The problem with this code is that the first representation is not available
when it is retrieved later, only the text representation is. If I comment
out the second Set call the first format is available. If you are supposed
to add mutliple fomats, which I really need to do, how do you do it without
overwriting the previous data you put on the clipboard?
 
G

Guest

I figured it out:

DataObject dataObj = new DataObject();
Build Format...

dataObj.SetData(fmtCdsCell.Name, object);

Build a plain text representation...

dataObj.SetText(strText);

ClipBoard.SetDataObject(dataObj);
 

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