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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:41:12+00:00 2026-06-10T15:41:12+00:00

I’m trying to override a simple method within a standard TreeView control; public class

  • 0

I’m trying to override a simple method within a standard TreeView control;

public class treeView1 : TreeView
{
    protected override void OnMouseUp(MouseEventArgs e)
    {
        MessageBox.Show("Are we getting here?");
        base.OnMouseUp(e);
    }
}

It seems simple, but I can’t understand why it’s not being called. I call inherit from the TreeView control, and do a basic override. The TreeView is called treeView1 and responds to event method on it’s parent class, just not the overridden ones, why!?

Also I don’t want to create a custom user-control, just want to keep this basic. Thanks.

EDIT: I created the treeview in the Form1.Designer.cs

private System.Windows.Forms.TreeView treeView1;

& is initialised with the following;

// 
// treeView1
// 
this.treeView1.Location = new System.Drawing.Point(13, 316);
this.treeView1.Name = "treeView1";
this.treeView1.Size = new System.Drawing.Size(539, 474);
this.treeView1.TabIndex = 2;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
this.treeView1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.treeView1_MouseUp);
  • 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-06-10T15:41:13+00:00Added an answer on June 10, 2026 at 3:41 pm

    With this declaration, you are creating a new “type”, which is derived from TreeView and which can be used to declare instances that behave in the customized way.

    You didn’t show your usage code (EDIT – now you have), but I would bet a nickel that the actual control that displays on the form is still declared:

    protected System.Windows.Forms.TreeView treeView1;
    

    If that is indeed the case, you’re not using your derived type; the actual control is still an instance of the built-in TreeView class, not your derived class. So, at runtime, your object’s method won’t be called because your object isn’t even being used.

    Instead, you must declare the control as an instance of your new class:

    protected treeView1 treeView1;
    

    … and then also make sure it is instantiated as such:

    private void InitializeComponents()
    {
        ...
        treeView1 = new treeView1(); //not System.Windows.Forms.TreeView
        ...
    }
    

    To avoid confusion between the type and the instance of that type, I would define the derived class using UpperCamelCase naming convention: TreeView1.

    EDIT: Thanks for showing the usage. It’s definitely what I thought it was; your variable treeView1 is an instance of the built-in System.Windows.Forms.TreeView, not your custom derived treeView1 class. There is a big difference between the name of a class and the name of the instance of a class. The proper declaration should be:

    private treeView1 treeView1;
    

    … and I reiterate that the class name should use UpperCamelCase naming convention:

    public class TreeView1 : TreeView
    {
        protected override void OnMouseUp(MouseEventArgs e)
        {
            MessageBox.Show("Are we getting here?");
            base.OnMouseUp(e);
        }
    }
    
    ...
    //now when declaring it it'll be easier to tell the difference
    private TreeView1 treeView1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to select an H1 element which is the second-child in its group

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.