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 568337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:10:41+00:00 2026-05-13T13:10:41+00:00

Being relatively new to C#, I’ve been researching custom events recently, and while I

  • 0

Being relatively new to C#, I’ve been researching custom events recently, and while I think I now understand the basic pieces required to setup a custom event, I’m having trouble determining where each piece belongs. Specifically, here’s what I’m trying to do.

I have a tree control that represents the layout of an internal data structure. When the data is rearranged in the tree (via drag/drop), I need to rearrange the underlying data structure to match.

So, I’m attempting to fire my own, custom event from within the “Drop” event handler of the tree control (after I’ve validated the drop). The idea being that a subscriber to my event would handle the reordering of the underlying data.

I’m just struggling to determine where each piece of event machinery should be created and/or used.

If someone could provide me with a basic sample of the above, that’d be great. For instance, maybe a simple example that sets up and fires a custom event from within an existing button_click event. That would seem to be a good simulation of what I’m trying to do.

Also, if my approach to the problem seems completely wrong, I’d like to know that also.

  • 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-13T13:10:42+00:00Added an answer on May 13, 2026 at 1:10 pm

    You need to declare the prototype for your event handler, and a member variable to hold event handlers that have been registered in the class owns the treeview.

    // this class exists so that you can pass arguments to the event handler
    //
    public class FooEventArgs : EventArgs
    {
        public FooEventArgs (int whatever) 
        { 
           this.m_whatever = whatever; 
        }
    
        int m_whatever;
    }
    
    // this is the class the owns the treeview
    public class MyClass: ...
    {
        ...
    
        // prototype for the event handler
        public delegate void FooCustomEventHandler(Object sender, FooEventArgs args);
    
        // variable that holds the list of registered event handlers
        public event FooCustomEventHandler FooEvent;
    
        protected void SendFooCustomEvent(int whatever)
        {
            FooEventArgs args = new FooEventArgs(whatever);
            FooEvent(this, args);
        }
    
        private void OnBtn_Click(object sender, System.EventArgs e)
        {
            SendFooCustomEvent(42);
        }
    
        ...
    }
    
    // the class that needs to be informed when the treeview changes
    //
    public class MyClient : ...
    {
        private MyClass form;
    
        private Init()
        {
           form.FooEvent += new MyClass.FooCustomEventHandler(On_FooCustomEvent);
        }
    
        private void On_FooCustomEvent(Object sender, FooEventArgs args)
        {
           // reorganize back end data here
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Being relatively new to the .net game, I was wondering, has anyone had any
Being relatively new to functional programming, I expend lots of energy wondering is this
Being new to test based development, this question has been bugging me. How much
I've been stuck on this problem for a while now and have tried my
I'm relatively new to python and scipy, being a convert from MATLAB. I was
Being relatively new to backbone.js, I've created several small tests from a simple model
I'm relatively new to OpenGL and have been using the GLTools library it provides.
Being really new to wx, I'm wondering if there is an IDE (especially for
I'm relatively new to Perl, writing some XML parsing scripts. I have done two
I'm relatively new to python and know very little syntax, but I'm willing to

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.