CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2004
    Posts
    5

    Question Problems copying object to clipboard

    Hello.

    We have a problem copying an object to the clipboard.

    to do this, we write: Clipboard.SetDataObject(o)
    where o is our object.

    Our object is inherited from UserControl.

    When we try to retrieve the object from the clipboard, it is of the right type, but it is null.

  2. #2
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Problems copying object to clipboard

    The object that is added to the Clipboard needs to be serializable. eg.
    Code:
    [Serializable]
    public class YourData
    {
    .
    .
    }
    
    Clipboard.SetDataObject(new DataObject(new YourData()));
    
    IDataObject dataObject = Clipboard.GetDataObject();
    object data = dataObject.GetData(typeof(YourData));
    Useful? Then click on (Rate This Post) at the top of this post.

  3. #3
    Join Date
    Sep 1999
    Posts
    67

    Re: Problems copying object to clipboard

    What if the object is serilizable and it returns null anyway. Anyone have any idea what is wrong?

    Thanks

    Anders

  4. #4
    Join Date
    Mar 2005
    Location
    マレーシア
    Posts
    155

    Re: Problems copying object to clipboard

    I`m having the exact same problem after doing everything mentioned here. Anyone els has found a solution?
    Ai nò mai speling sùks, bùt ai du it mainfuli
    http://www.geocities.jp/juuhassai/i_rouseiji.html

  5. #5
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

  6. #6
    Join Date
    Mar 2005
    Location
    マレーシア
    Posts
    155

    Re: Problems copying object to clipboard

    this is the object i`m trying to place on the clipboard

    Code:
    [Serializable]
    public abstract class PageItem : UserControl
    {
    
    }
    to place the object on the clipboard, i do this

    Code:
    Clipboard.SetData ( "PageItem", pageItemObject ) ;
    The following method call returns true

    Code:
    Clipboard.ContainsData ( "PageItem" ) ;
    However, when i do this, it returns null

    Code:
    Clipboard.GetData ( "PageItem" ) ;
    Can`t figure out why...
    Ai nò mai speling sùks, bùt ai du it mainfuli
    http://www.geocities.jp/juuhassai/i_rouseiji.html

  7. #7
    Join Date
    Mar 2007
    Posts
    274

    Re: Problems copying object to clipboard

    I'm sorry I dont mean to clog up your thread, I'm still very new to c#.


    I just got done serializing a generic queue of struct's. In my reading it says you cant serialize an inherited class. Does that help any?

    http://msdn2.microsoft.com/en-us/lib...attribute.aspx
    Last edited by Traps; April 17th, 2007 at 09:39 PM.

  8. #8
    Join Date
    Mar 2005
    Location
    マレーシア
    Posts
    155

    Re: Problems copying object to clipboard

    Ah, thanks for the input. That might be the problem
    Ai nò mai speling sùks, bùt ai du it mainfuli
    http://www.geocities.jp/juuhassai/i_rouseiji.html

  9. #9
    Join Date
    May 2006
    Location
    Norway
    Posts
    1,709

    Re: Problems copying object to clipboard

    Quote Originally Posted by Traps
    I just got done serializing a generic queue of struct's. In my reading it says you cant serialize an inherited class.[/url]
    Well you cannot serialize a class that is inherited from a class that does not implement serializing. Therefore you can not serialize a class that inherits from UserControl.

    Regards,

    Laitinen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured