C# Cut/Copy & Paste objects
<p>This is a 2 parter.</p>

<p>First I am having a heck of a time getting the paste part of a copy and paste operation to work. </p>

<p>I have a method that copies information to the Clipboard, works perfectly.</p>

<pre><code>private void CopyData(string format, object data, string text)
    {
        bool addedData = false;
        DataObject copyData = new DataObject();

        if (!string.IsNullOrEmpty(text))
        {
            copyData.SetData(DataFormats.Text, text);
            addedData = true;
        }

        if (!string.IsNullOrEmpty(format) &amp;&amp; data != null)
        {
            copyData.SetData(format, false, data);
            addedData = true;

            //this is only for testing
            object obj = null;
            if (copyData.GetDataPresent(format))
                obj = (object)copyData.GetData(format);
        }

        if (addedData)
            Clipboard.SetDataObject(copyData, true);
    }
</code></pre>

<p>When I check that the data was added the object (obj) is not null.</p>

<p>However when I then go to paste the data from a different method using the same format key I get null, every time.</p>

<pre><code>private void PasteFromClipboard()
    {
        object obj = null;
        IDataObject paste = null;
        if (Clipboard.GetDataObject().GetDataPresent("mydatatype"))
            obj = (object)Clipboard.GetDataObject().GetData("mydatatype");
        else
            return;

        if (obj == null)
            throw new NullReferenceException("Could not gather information from the 
    }
</code></pre>

<p>I have tried everything that I can think of and it just doesn't make sense. I created an array of strings to capture all of the format keys the DataObject was holding and "mydatatype" was the first one. I have tried casting, not casting, using <code>(Clipboard.GetDataObject().GetData("mydatatype") as object)</code> and I just cannot figure it out. I know that there is data there because I can go to NotePad and paste the text that I copied along with the object. </p>

<p>Any thoughts as to why I would be able to get the data in one method, but not another?</p>

<p>Secondly I was wondering how I would go about making a Cut &amp; Paste operation work between two of my windows. I am thinking about something like Excel, where if only the text is pasted the data will remain, however if the objects are pasted then the source will be deleted.</p>

<p>Thanks
Patrick.</p>
