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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:43:21+00:00 2026-06-10T09:43:21+00:00

I have TreeView with different level TreeNodes I added same ContextMenuStrip to all parent

  • 0

I have TreeView with different level TreeNodes
I added same ContextMenuStrip to all parent TreeNodes and i want to get possibility to delete all child TreeNodes by opening that ContextMenuStrip and pressing “Delete all”

private void btn_delete_all_objects_Click(object sender, EventArgs e)
{
    ToolStripMenuItem tsmi = (ToolStripMenuItem)sender; //that way i receive button "Delete all"
    ContextMenuStrip cms = (ContextMenuStrip)tsmi.Owner; //this is ContextMenuStrip where this button...
    TreeView tw = (TreeView)cms.SourceControl; //i can get TreeView :( BUT I NEED TreeNode!
    TreeNode tn = tw.SelectedNode; //bah... if i select some of child nodes, then right click to open menu on parent, selected node is still that child
}

And i don’t know how to get that TreeNode where user clicked to open menu
Any ideas?

  • 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-10T09:43:22+00:00Added an answer on June 10, 2026 at 9:43 am

    you can use HitTest() method from tree view to find the node, like this,

    var hitTest = treeView1.HitTest(treeView1.PointToClient(new Point(contextMenuStrip1.Left, contextMenuStrip1.Top)));
    if (hitTest.Node != null)
    {
        // Place your code to delete nodes
    }
    

    or you can focus the node on which the mouse clicked and use treeView1.SelectedNode property to manipulate in your menu items. By this way you can avoid using HitTest() on every context menu item…

    private void treeView1_MouseDown(object sender, MouseEventArgs e)
    {
        var hitTest = treeView1.HitTest(treeView1.PointToClient(e.Location));
        if (hitTest.Node != null)
        {
             treeView1.SelectedNode = hitTest.Node;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a treeview in my C# code. I want to replace all existing
I have a treeview (winforms) which have different item types on it. I have
I have a TreeView that permits the user to select different items. The display
Suppose I have a treeview, where each treenode contains an id for a different
I have a TreeView that is bound to a XmlDataSource control. I've added some
I have a treeView , and i want to know if some node can
As title, is it possible? I have seen in TreeView you can defines different
Hi all i have main form with a treeview control with a set of
Hey all, I've noticed that if I have a style setup for a treeview,
I have a question regarding the ASP.NET 3.5 Treeview and Treenodes. I'd like 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.