Drag & Drop - Passing Objects Between Processes

B

Barry Moon

Hi

Can anyone give me any help with passing an object across processes, via drag and

drop?

I've written a custom ListView control, which supports dragging and dropping of

its items. The drag and drop works fine within the same application, but fails

when dragging between two instances of the app.

I'm using my own collection class, called Series (derived from CollectionBase),

which holds simple objects representing the list items that are being dragged.

When the drag operation starts, I call DoDragDrop and supply a new instance of a

Series collection as the data.

In the DragDrop event, I retreive the data back from the arguments using GetData.

When dragging within the same application, I receive an object which can be

casted to a Series object, and all is well.

However, when dragging between two application instances, I receive an object

that appears to be a "System.__ComObject" - which I'm not able to cast back to a

Series object.

I've read several newsgroup postings around this area, and most seem to suggest

implementing the ISerializable interface on the object being passed. I've tried

this in the Series class - but it didn't seem to make any difference to the

behaviour I was seeing.

I'd really appreciate any help or hints with this - I've been stumped for days!

Thanks in advance,

Barry Moon
 
N

Nicholas Paldino [.NET/C# MVP]

Barry,

Did you implement the serialization correctly? You have to add the
Serializable attribute, and if you are implementing ISerializable for custom
serialization, you have to provide a special constructor.

Can you post some of your code?
 
B

Barry Moon

Nicholas

Well, I have to admit that my implementation of ISerializable just
provides empty methods at the moment. I assumed that as long as my
code created a Series object, even though it was empty, that would
prove that the casting worked. Once I'd got the cast working I
intended to add the full implementation afterwards. Perhaps this was a
mistake...?

Here's the serialization code for my Series class:


public class Series : System.Collections.CollectionBase,
ISerializable
{
...

/// <summary>
/// Default constructor.
/// </summary>
public Series() : base()
{
}

/// <summary>
/// DeSerialization constructor.
/// </summary>
/// <param name="info">Stores data required for
deserializing.</param>
/// <param name="ctxt">Serialization details.</param>
public Series(SerializationInfo info, StreamingContext ctxt) :
base()
{
//Get the values from info and assign them to the appropriate
properties
}

...

/// <summary>
/// Serialization function.
/// </summary>
/// <param name="info">Stores data required for
deserializing.</param>
/// <param name="ctxt">Serialization details.</param>
public void GetObjectData(SerializationInfo info, StreamingContext
ctxt)
{
//Describe this object to the info here...
}

...

}

I appreciate your help.

Thanks,
Barry

(P.S. - Sorry about the nasty double-spacing in my original message!)
 

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