I'm trying to add copy/paste to an application that edits items. Having a copy of the data for a set of selected items, should enable duplicating them or transporting them to another instance of the program. I've tried this:
const string MyClipboardFormat = "MyClipboardFormat"
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
XmlDocument xdoc;
//add data of selected items
Clipboard.SetData(MyClipboardFormat,xdoc);
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
XmlDocument xdoc = Clipboard.GetData(MyClipboardFormat) as XmlDocument;
if (xdoc == null)
throw new Exception("Clipboard does not contain MyClipboardFormat");
//read item data from xdoc
}
I've googled but found only bits about using GetDataObject/SetDataObject, equivalent to what appears to be going on anyway, if I use reflector to look what GetData/SetData does.
Should I register the clipboard format string somewhere?