title: C#: When retrieve data from clipboard then getting NULL always
body: <p>I have store the instance of my class in clipboard and when retrieve the same from clipboard then getting null always. i marked my class <code>[Serializable]</code> but still no luck. i am not being able to find out where i made the mistake. Here is my code. please have a look and tell me where i made the mistake and what to change in code as a result i should be able to retrieve the object i stored in clipboard. Thanks</p>
  <pre><code>//Save object to clipboard
  private void BtnSet_Click(object sender, EventArgs e)
  {
      NodeCollection ndCollection = new NodeCollection();
      TunerDetails tds = null;
      selectednode = tvCsmTuner.SelectedNode;
      if (selectednode == null) return;
  
      if (selectednode != null)
      {
          ndCollection.Name = selectednode.Text;
          ndCollection.Text = selectednode.Text;
          ndCollection.Tag = selectednode.Tag;
  
          foreach (TreeNode node in selectednode.Nodes)
          {
              ndCollection.Nodes.Add(new NodeCollection { Name = node.Text, Text = node.Text, Tag = node.Tag });
          }
  
          DataObject data = new DataObject();
          data.SetData(ndCollection);
          Clipboard.SetDataObject(data);
  
      }
  
      RemoveNode();
  
  }
  
  
  //Read object back from clipboard
  private void BtnGet_Click(object sender, EventArgs e)
  {
          DataObject retrievedData = (DataObject)Clipboard.GetDataObject();
          if (retrievedData.GetDataPresent(typeof(NodeCollection)))
          {
              NodeCollection ndCollection1 = retrievedData.GetData(typeof(NodeCollection)) as NodeCollection;
              if (ndCollection1 != null)
              {
                  MessageBox.Show(ndCollection1.Name);
              }
          }
  }
  
  
  [Serializable]
  public class NodeCollection 
  {
      public NodeCollection() {
          Nodes = new List&lt;NodeCollection&gt;();
      }
      
      #region PROPERTIES
      public string Name { get; set; }
      public string Text { get; set; }
      public object Tag { get; set; }
      public List&lt;NodeCollection&gt; Nodes { get; set; }
      #endregion
  }
  </code></pre>
  <p>In same application when i try to same object in clipboard this way then it worked. below code worked. so now i more confused that customer data getting store and retrieve in clipboard but my nodecollection class is not getting retrieve from clipboard.</p>
  <pre><code>DataObject mydata = new DataObject();
  Customer c = new Customer(&quot;Customer as Customer object&quot;);
  c.Nodes.Add(new Customer { Name = &quot;Hello&quot; });
  mydata.SetData(c);
  Clipboard.SetDataObject(mydata);
  
  DataObject MyretrievedData = (DataObject)Clipboard.GetDataObject();
  if (MyretrievedData.GetDataPresent(typeof(Customer)))
  {
      Customer customer =
          MyretrievedData.GetData(typeof(Customer)) as Customer;
      if (customer != null)
      {
          MessageBox.Show(customer.Name);
      }
  }
  
  [Serializable]
  public class Customer
  {
      public Customer() { }
      private string nameValue = string.Empty;
      public Customer(String name)
      {
          nameValue = name;
          Nodes = new List&lt;Customer&gt;();
      }
      public string Name
      {
          get { return nameValue; }
          set { nameValue = value; }
      }
  
      public List&lt;Customer&gt; Nodes { get; set; }
  }
  </code></pre>