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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:46:17+00:00 2026-06-12T23:46:17+00:00

I am very new to .NET and I had to write a program in

  • 0

I am very new to .NET and I had to write a program in which there is a TreeView with different kind of nodes, Each kind of node has a different ContextMenuStrip, So I create multiple kind of ContextMenuStrip and assign then to different kind of TreeNode. Now my question is, when user show a context menu how should I find which TreeNode was the node that cause ContextMenuStrip to show. I try to use ContextMenuStrip.SourceControl but it return a TreeView and it never help me, because I know that my source is TreeView I want to know which node of the view! Now should I use some kind of hit test? and if yes what about ContextMenu that shown using keyboard?

  • 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-12T23:46:20+00:00Added an answer on June 12, 2026 at 11:46 pm

    You may use Tag property to “link” the source nodes.
    For example, in your form’s Load event handler:

        private void Form1_Load(object sender, EventArgs e)
        {
            TreeNode rootNode = treeView1.Nodes[0];        
    
            rootNode.Nodes[0].ContextMenuStrip = contextMenuStrip1;
            contextMenuStrip1.Tag = rootNode.Nodes[0];
    
            rootNode.Nodes[1].ContextMenuStrip = contextMenuStrip2;
            contextMenuStrip2.Tag = rootNode.Nodes[1];
        }
    

    Then you can bind all ContextMenuStrip controls’ Opened event handlers to one method, as below:

        private void contextMenuStrip_Opened(object sender, EventArgs e)
        {
            ContextMenuStrip cms = sender as ContextMenuStrip;
            TreeNode aNode = cms.Tag as TreeNode;
            if (aNode != null)
            {
                MessageBox.Show(aNode.Text);
            }
        }
    

    There might be better ways to do it, but I think this should be able to solve your problem.

    Updated 2012-10-17:

        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                contextMenuStrip1.Tag = e.Node;
            }
        }
    
        private void contextMenuStrip1_Opened(object sender, EventArgs e)
        {
            ContextMenuStrip cms = sender as ContextMenuStrip;
            TreeNode aNode = cms.Tag as TreeNode;
            if (aNode == null)
            {
                aNode = treeView1.SelectedNode;
            }
            MessageBox.Show(aNode.Text);
        }
    
        private void contextMenuStrip1_Closed(object sender, ToolStripDropDownClosedEventArgs e)
        {
            ContextMenuStrip cms = sender as ContextMenuStrip;
            cms.Tag = null;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to ASP.net, and I had to fix a issue in and
I'm very new to ASP.NET MVC, so forgive me if this is something I
I am basically a .net developer and very new to jsf, so it may
I am relatively new to ASP.NET MVC, and am very impressed with the clarity
I'm very new to .Net and WPF and have a problem. The code is
I'm new in VB.NET, but for C, C++, C# and other languages I had
Hi I'm building a very simple search system using ASP.NET MVC. I had it
I am very new to PHP. The code below has been cobbled together from
Very new to python and can't understand why this isn't working. I have a
Very new to C++ and Cocos2d-x but I was just toying around with CCArray

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.