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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:52:51+00:00 2026-05-24T15:52:51+00:00

An event handler can be removed with the following code in the button click

  • 0

An event handler can be removed with the following code in the button click event.

Button btn = new Button();
this.Controls.Add(btn);
btn.Click += (o, x) =>
{
    Button b = o as Button;
    FieldInfo eventclick = typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
    object eventValue = eventclick.GetValue(b);
    PropertyInfo events = b.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance);
    EventHandlerList eventHandlerList = (EventHandlerList)events.GetValue(b, null);
    eventHandlerList .RemoveHandler(eventValue, eventHandlerList [eventValue]);
    MessageBox.Show("Test");
};

But I want to remove the event handler from the vgridcontrols CellValueChanged event. What do I have to write for “EventClick” in the following?

FieldInfo eventclick = typeof(Control).GetField(
    "EventClick",
    BindingFlags.Static | BindingFlags.NonPublic);
  • 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-24T15:52:52+00:00Added an answer on May 24, 2026 at 3:52 pm

    You cannot reliably remove an event handler from an event unless you already have an “equal” delegate you can use with -= in the normal way.

    Getting fields with reflection and hacking around at them is a clear violation of encapsulation and makes your code extremely fragile. I would strongly recommend against doing it.

    It’s not clear what you mean by “vgridcontrols” (DataGridView?) but whatever solution you come up with is bound to be implementation-specific – and that implementation could easily change with the next version of whatever it is.

    Instead, put time into coming up with a design where either you don’t need to remove the event handler at all, or you keep a reference to the handler and can remove it in the normal way.

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

Sidebar

Related Questions

To create a new event handler on a control you can do this c.Click
How can I use command line arguments in a creationComplete event handler? It seems
I want to attach a 'click' event handler to the first child of an
In Firefox when you add an onclick event handler to a method an event
Given the following code Public Shared Sub DoAsyncAction() Using asmxProxy As New MyAsmxServiceProxy() AddHandler
The following code snippet is from book Effective C#, public event AddMessageEventHandler Log; public
I have some event handler on a boundary class that manages a persistence mechanism
I have a simple event handler with a ItemAdding event that changes a column
I have a sharepoint event handler which I want to activate for a single
I've implemented my own event handler and added it to the selection model of

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.