Can't get object out of the clipboard

G

Guest

I put an instance of a class of mine in the clipboard and when I try to get it back the clipboard reports that it contains the format I am asking for, but then returns null

The code is as following

// copy
IDataObject iData = new DataObject()
// myClass is [Serializable] and contains only string and int public member
myClass data = new myClass()
iData.SetData( typeof( myClass ), data )
Clipboard.SetDataObject( iData, false )

// past
IDataObject iData = Clipboard.GetDataObject()
if ( iData.GetDataPresent( typeof( myClass ) )

// here null is always returne
myClass data = (myClass)iData.GetData( typeof( myClass ) )


I have read postings from other people in various places asking help on variations of this problem, but there has never been a conclusive answer. Could it be a bug?

Thanks
Raul Rosentha
 
J

Janaka

I thought that the clipboard could only store value types, hence why your
not able to set and retrieve a reference type.

Raul Rosenthal said:
I put an instance of a class of mine in the clipboard and when I try to
get it back the clipboard reports that it contains the format I am asking
for, but then returns null.
The code is as following:

// copy
IDataObject iData = new DataObject();
// myClass is [Serializable] and contains only string and int public members
myClass data = new myClass();
iData.SetData( typeof( myClass ), data );
Clipboard.SetDataObject( iData, false );

// paste
IDataObject iData = Clipboard.GetDataObject();
if ( iData.GetDataPresent( typeof( myClass ) ) )
{
// here null is always returned
myClass data = (myClass)iData.GetData( typeof( myClass ) );
}

I have read postings from other people in various places asking help on
variations of this problem, but there has never been a conclusive answer.
Could it be a bug?
 
G

Guest

Thank you for your reply

I tried making myClass a struct (which should make it a value type), but the problem didn't go away
I think that I saw same example in MSDN that uses objects (i.e. instances of a class) to put data in the clipboard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top