I have a problem I hope you folks can help me with.
I have an application that is using a tab-based interface, with the ability
for users to drag an item from a ListBox onto the tab control. This will
create a new tab, put a new instance of the proper UserControl into the tab,
and populate said UserControl with the data culled from the drop source.
Because of the nature of this application, the particular UserControl that
will be placed in the tabpage is constructed "on the fly" - the control is
created, linked to event handlers, and added to the tab control all in code.
I'm using a third-party tab control, but it's conceptually no different than
the MS tab control. I have the tab control's events hooked during
design-time, but since they can drag anywhere in the general tab page, each
page's UserControl has to have its drag/drop events hooked as well -
otherwise, once a tab page is created, the only place the user can
successfully drop is on the actual tabs (not the user experience I'm looking
for.)
My problem is that the UserControls I'm using all have child controls in
them, and while I can programmatically hook the UserControl's drag/drop
events, that hookup doesn't apply to its child controls. So when the user
drags their selection over the UserControl, all is well - but once they hit
a child control, they get a "you can't drop here" reaction, since the child
controls are not hooked to the same event(s) as the UserControl itself. It
makes for a very weird user experience.
I don't want to hardcode the drag/drop functionality within the specific
UserControls, since if I change the behavior in the form, I have to hit
every UserControl as well. I also don't want to try and implement some sort
of "For Each c as Control in UserControl..." loop, since some controls don't
support drag/drop functionality, and I don't want to write a lot of
type-testing code to figure out what I should hook up.
My intial thought was to try and develop some sort of method where I could
trap the assignment of the event delegate and propagate that to the child
controls, but (a) that's backwards to the Windows model - events move up the
window chain, not down - and (b) I could find nothing to help me in that
regard. So, now I'm looking at trying to code all my child controls to
raise the UserControl's appropriate drag/drop events in response to theirs,
so that they "bubble up" the chain - through the system-defined drag/drop
event for the UserControl. That way, my AddHandler hookup would see it, and
the .NET drag/drop code would take over from there. But RaiseEvent won't
raise a system-defined event on a control, and I have had no luck in trying
to create a delegate off the system events.
Does anyone have any idea how to make this work? Am I going about this the
wrong way?
TIA
- Scott