Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7195371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:33:58+00:00 2026-05-28T20:33:58+00:00

I am trying to copy an object onto the windows clipboard and off again.

  • 0

I am trying to copy an object onto the windows clipboard and off again. My code is like this:

Copy on to clipboard:

Clipboard.Clear();
DataObject newObject = new DataObject(prompts);
newObject.SetData(myString);
Clipboard.SetDataObject(newObject);

Where prompts is a List<Data.Sources.PromptResult> collection.

Copy off clipboard:

IDataObject dataObject = System.Windows.Forms.Clipboard.GetDataObject();
if (dataObject.GetDataPresent(typeof(List<Data.Sources.PromptResult>)))
{
  Type type = typeof(List<Data.Sources.PromptResult>);
  Object obj = dataObject.GetData(type);
  return (List<Data.Sources.PromptResult>)dataObject.GetData(type);
}

The GetFormats() shows the format as being in the list and the GetDataPresent(List<Data.Sources.PromptResult>) returns true but if I try to get the object out of the Clipboard class with GetData(List<Data.Sources.PromptResult>) I get a return of null.

Does anyone have any idea what might be wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T20:33:58+00:00Added an answer on May 28, 2026 at 8:33 pm

    OK I tried to add list of my user type to clipboard and get it back…
    Here is what I tried:

    My User Class:

    public class User
    {
       public int Age { get; set; }
       public string Name { get; set; }
    }
    

    Rest of Code:

    // Create User list and add some users
    List<User> users = new List<User>();
    users.Add(new User { age = 15, name = "Peter" });
    users.Add(new User { age = 14, name = "John" });
    
    // Lets say its my data format
    string format = "MyUserList";
    Clipboard.Clear();
    
    // Set data to clipboard
    Clipboard.SetData(format, users);
    
    // Get data from clipboard
    List<User> result = null;
    if (Clipboard.ContainsData(format))
        result = (List<User>)Clipboard.GetData(format);
    

    …and result was null 🙂
    …until I marked User class as Serializable

    [Serializable]
    public class User
    { 
        //...   
    }
    

    After that my code worked.
    Ok its not the answer but maybe it helps you some how.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to copy a file using this - private void button1_Click(object sender,
I have some code that performs a deep copy using Object.clone, but I'm trying
I'm trying to make a deep copy of an object, including a GregorianCalendar instance.
I'm trying to make a copy constructor for an object and one of the
I'm trying to make a copy function and add it to the object's prototype.
I'm trying to copy files to C:\Windows\System32 using cygwin bash. When I copy files
I'm trying to copy a custom object from a RDC window into host (my
I am trying to copy some property values from one object to another (both
I'm trying to copy the selected item's filename and its path to the clipboard
I feel like a moron asking this, but since I'm a new to developing,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.