GetDataPresent and interfaces (DragDrop)


C

Chetan Mistry

Is is possible to check to see during a drag drop operation if the
object being dropped implements a particular interface?

For example, if I have the following class which implements
IMyInterface:

class MyClass : IMyInterface
{
// implementation ommitted
}

Then when I start dragging I call DoDragDrop() like this:

MyClass myClass = new myClass();
IMyInterface myInterface = myClass as IMyInterface;
DoDragDrop( myInterface, DragDropEffects.Copy );

Then when I get my DragEnter event I want to check if the data
supplied implements IMyInterface. e.g.

if ( e.Data.GetDataPresent( typeof (IMyInterface) ) .....

This returns false but if a do "typeof(MyClass) it works fine.

How can I check to see if the item being dropped implements a specific
interface?

Thanks.
Chet
 
Ad

Advertisements

M

Matt Berther

Hello Chetan,

The is keyword...

if (myVar is IMyInterface)
{
// do something
}
 

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