Re: Cascading delegates

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Ben Voigt [C++ MVP] wrote:


"Amien Crombie" <acrombie@xxxxxxxxxxx> wrote in message news:exMuXByvJHA.5584@xxxxxxxxxxxxxxxxxxxxxxx
Hi

I have a Usercontrol (child) that is part of another usercontrol (Parent). In my child usercontrol, I use a delegate to pass an event with some data (a custom EventArgs class) to the parent usercontrol. This parent usercontrol then creates a duplicate delegate that passes this to my windows form.
This all works but maybe there is a better way of doing this ??

Using a manual event, you can directly subscribe handlers to the control which fires the events, without the intermediate containers ever having to forward them.

My parent usercontrol is nothing else than a container (FlowLayoutPanel) for my child usercontrols.
When my app starts, it reads a database and creates child usercontrols and places it on the parent usercontrol. This includes creating the event handler coming from each child usercontrol.
Any advise would be appreciated.
Thanks
Amien.
Cape Town
www.tlabs.ac.za


Hi Ben

Yes, that make sense now that I have played around with delegates/events a bit.
The other concern was that I wrote the event handling code inside the usercontrol. If I create the eventhandlers in my form, my form becomes too messy with all the event handlers.
Therefore I'm using a delegate in the usercontrol to pass data via a custom eventArgs class, to any form that wants to subscribe to this delegate.
But I'm very new to C# and are grateful for any help. I'm also looking at the MVC pattern suggested by Morten and it seems to fit our needs.

Thanks
Amien
.



Relevant Pages

  • RE: Cascading delegates
    ... if the parent Control displays a parent object and the ... UserControl displays a child object, the parent object may subscribe to ... In my child usercontrol, I use a delegate to pass an event ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Cascading delegates
    ... I have a Usercontrol that is part of another usercontrol. ... In my child usercontrol, I use a delegate to pass an event with some data to the parent usercontrol. ...
    (microsoft.public.dotnet.languages.csharp)
  • Cascading delegates
    ... I have a Usercontrol that is part of another usercontrol. ... In my child usercontrol, I use a delegate to pass an event with some data to the parent usercontrol. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Can you load a usercontrol into another usercontrol?
    ... just keep in mind that you need to time your events well in the control event hierarchy. ... Sometimes an action in a usercontrol that works when embedded in a page may be a bit off when placed inside another user control. ... You click a link in the parent usercontrol to select a different set of data to show in the child usercontrol, but the timing of the events is off so the child usercontrol doesn't update properly and ends up a step behind the parent. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Strange permission issue with a UserControl
    ... The UserControl in the WinForms ... > implements the delegate as an event. ... > I'll post the error messages later today... ... Does the UserControl inherit from a base class ...
    (microsoft.public.dotnet.security)