DragEventArgs and GetDataPresent with abstract base class

  • Thread starter Thread starter MarkR
  • Start date Start date
M

MarkR

Hello:

I am trying to build a drag-and-drop operation with a control derived from
my abstract base class. The control is either a PictureControl or a
PictureGroupControl, both of which have PictureComponentControl as their
superclass.

When handling a DragOver event, I'd like to treat the dragged object as a
PictureComponentControl without having to explicity test for whether the
object is a PictureControl OR a PictureGroupControl, but
GetData/GetFormats/GetDataPresent seem to only work with the subclass, not
with the superclass. I've even tried explicitly casting the object when I
begin the DoDragDrop() operation, but even then it doesn't seem to stick.

Any advice for me? I know I could test for both subclasses explicitly, but
that seems like bad OO -- then, in the future when I invent a
SuperPictureControl, I'll have trouble. Is there a better way to do this,
perhaps using Reflection or an Interface?

Thank you,
/m
 
The drag source provides information about the available types of
information by using just a simple string description. The .NET
implementation will therefore get the class name and use that as a unique
description that accurately describes what is available. It is not a Type
object that can be tested against a base class.

One way around this, although it is probably not worth the effort in your
case, would be to create a helper class that contains a reference to the
actual data instance. You always pass the helper class across during your
drag and drop. Then you only ever ask for that one known helper class when
testing the source. Once extracted and recreated as an object you can then
get the actual object from the helper class using a property.

Phil Wright
Follow the startup of my microISV at...
http://componentfactory.blogspot.com
 
Thank you very much; if it's a string description of the data, then the
behavior I saw makes perfect sense.

/m
 
Back
Top