views:

316

answers:

1

C# Winforms 3.5

I have a list of user controls all derived from one base class. These controls can be added to various panels and I'm trying to implement the drag-drop functionality, the problem I'm running in to is on the DragDrop event.

The DragEventArgs: e.Data.GetData(typeof(baseClass)) doesn't work. It wants:

e.Data.GetData(typeof(derivedClass1))
e.Data.GetData(typeof(derivedClass2)) etc...

Is there a way I can get around this, or a better way to architect it?

+3  A: 

You can wrap the data in a common class. For example, assuming your base class is called DragDropBaseControl

public class DragDropInfo
{
  public DragDropBaseControl Control { get; private set; }

  public DragDropInfo(DragDropBaseControl control)
  {
    this.Control = control;
  }
}

And then the drag drop can be initiated with the following in the base class

DoDragDrop(new DragDropInfo(this), DragDropEffects.All);

And you can access the data in the drag events using the following

e.Data.GetData(typeof(DragDropInfo));

Have I understood your requirement correctly?

Chris Taylor
I'll give it a try and get back, but it looks promising.
Dustin Brooks