Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:05+00:00 2026-05-23T16:55:05+00:00

I have a SelectionChanged event in class A that I want to relay through

  • 0

I have a SelectionChanged event in class A that I want to relay through class B. I assumed that declaring a SelectionChanged event in class B and assigning this EventHandler to A.SelectionChanged would cause B.SelectionChanged to trigger whenever A.SelectionChanged was triggered – this turned out to be false.

To be more clear, some code:

class A
{
   public event EventHandler SelectionChanged;

   public void TriggerSelectionChanged()
   {
      if (SelectionChanged != null) SelectionChanged(this, EventArgs.Empty);
   }
}

class B
{
   private A _a = new A();

   public A A { get { return _a; } }

   public event EventHandler SelectionChanged;

   public B()
   {
      A.SelectionChanged += SelectionChanged;
   }

   public static void Test()
   {
      B relayer = new B();
      bool wasRelayed = false;
      relayer.SelectionChanged += delegate { wasRelayed = true; };
      relayer.A.TriggerSelectionChanged();

      System.Console.WriteLine("Relayed: {0}", wasRelayed);
   }
}

This prints out “Relayed: false”.

What are the effects of adding an EventHandler to another EventHandler?

EDIT:
Note! I’m aware of that a solution to this is to relay the event through an delegate, function etc etc, but I’m mostly interrested in knowning what the effects of this code is.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:55:06+00:00Added an answer on May 23, 2026 at 4:55 pm

    It turns out that this is an effect from EventHandler being a Delegate. This class implements operator += through (or so I assume) using Delegate.Combine. The documentation of this function reads

    Concatenates the invocation lists of the specified multicast (combinable) delegates.

    What happens is that all handlers assigned to the EventHandler on the right side are added to the EventHandler on the left. In this case there’s zero handlers so nothing happens. However, if the order of things are changed such that B.SelectionChanged is assigned before B.SelectionChanged is connected to A.SelectionChanged things are hooked up correctly. However, removing an handler from B does not remove it from A so doing this should be highly frawned upon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QTableView that I need to get the selectionChanged event from. I
If I have a ComboBox that has a SelectionChanged event, it fires when I'm
I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
I have a DataGridCell that contains a ComboBox. I want, that when I fire
In particular I would like to know how to bind the 'SelectionChanged' event of
I have a observable collection of type Project, that I want to be displayed
This is my first post and I have am concerned that some might think
I have an app that has a ListBox of ListBoxes. I would like to
In the ComboBox.SelectionChanged event I want to know who changed the ComboBox value, the
If I have a control (combobox, with a SelectionChanged-event in code-behind) in DataGrid. So,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.