[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Displaying a Form When a Node in a TreeView is Right-Clicked

Posted on 2006-06-24
3
Medium Priority
?
299 Views
Last Modified: 2010-04-16
Can someone please provide me with an example of how to do this? I couldn't find any. There is no right mouse click event for the TreeView, for one thing.

All I want to do is pop up a form when a node in a tree view is right clicked.

Thanks!
0
Comment
Question by:marmaxx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 16977646
Use TreeView MouseDown event:

        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if ( e.Button == MouseButtons.Right )
            {
                // If you want to know what node is clicked, use the follwing code:

                Point p = treeView1.PointToClient(Control.MousePosition);
                TreeNode node = treeView1.HitTest(p).Node;   // can be null

                // Show form here, for example:
                Form1 form = new Form1();
                form.ShowDialog(this);
            }
        }
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16977649
Actually, this is simple way:

        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if ( e.Button == MouseButtons.Right )
            {
                TreeNode node = treeView1.HitTest(new Point(e.X, e.Y)).Node;   // can be null

                // Show form here, for example:
                Form1 form = new Form1();
                form.ShowDialog(this);
            }
        }
0
 
LVL 11

Accepted Solution

by:
vo1d earned 2000 total points
ID: 16980771
you dont need a new point object for the hittest, just use e.Location.
and you should select the clicked node, if you show a specific form for each clicked node.

        private void treeView1_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button == MouseButtons.Right)
            {
                TreeNode node = this.treeView1.HitTest(e.Location).Node;
                if(node != null)
                {
                    this.treeView1.SelectedNode = node;
                    //show form etc
                }
            }
        }
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question