0

Our Business Application is made out of many listviews to display data.

We already extended the "basic" listview to an "extendedListView" in order to add different functionality, like sorting, Column reordering and stuff.

Now, we also want to add stuff like "Options" and "Aggregations" to every listview.

So, we decided to create a "Wrapper" (In java known as Composite Component) that is made of the listview and several buttons, depending on what is enabled for the ListviewWrapper, i.e. Excel-Export, CSV Export, Aggregations and many more:

The "Wrapper" exposes the underlaying Listview, top and bottom-panel as a property:

public partial class ExtendedListViewWrapper : UserControl
    {
        public Panel TopPanel { get { return this.topPanel; } }
        public Panel BottomPanel { get { return this.bottomPanel; } }
        public ExtendedListView ExtendedListView { get { return this.extendedListView; } }

This works nice, and allows us to modify every Property of the included listview during design time, if the wrapper is added to some form:

enter image description here

However, The Designer only allows to modify the EVENTS of the Wrapper itself. I can't set the Double-Click-Event for the included listview in the same way.

I.e. I would Expect - as for properties - to have the following option in the designer:

...
DoubleClick
DragDrop
...
[+] ExtendedListView
    ...
    DoubleClick
    DragDrop
    ...

Do we need to manually write code, that takes care to call the included event handler, or is there just something we missed?

What would be the best practice to modify the event handlers of components included inside user components, if the handler should be dynamicly defined per "Outer component" within the designer?

dognose
  • 20,360
  • 9
  • 61
  • 107
  • You don't indicate in your post, but I'm assuming this is Winforms. Typically, the `UserControl` abstracts away the child controls, just as various built-in composite controls (e.g. `TextBox`, `NumericUpDown`, `ComboBox`, etc.) abstract away their children. You pick the limited subset of properties and events you actually need to expose, and delegate them to the children as needed via explicitly written ones in the `UserControl`. That said, if you're up for some extra work, you can get the children to participate in the design as well. See marked duplicates for examples of each strategy. – Peter Duniho Aug 08 '19 at 00:05
  • @PeterDuniho Yes, it's Winforms. Okay, that's odd. So i basicilly need to "re-route" every event-handler that's needed for the listview (explicit) to it's "wrapper" - and in the wrapper eventually take care, if the click is on `listview`, `topPanel` or `bottomPanel`... – dognose Aug 08 '19 at 07:15
  • Okay, shadowed the Wrappers `DoubleClick`-Eventhandler (and other events required): `public new event EventHandler DoubleClick { add { this.ExtendedListView.DoubleClick += value; } remove { this.ExtendedListView.DoubleClick -= value; } }` – dognose Aug 08 '19 at 07:47

0 Answers0