|
-
January 3rd, 2010, 07:06 PM
#1
[SOLVED] Right Click in TreeView not responding
C# WinForms.. trying to get a contextMenu to show in TreeView when I right click - but nothing is happening
Code:
private void mainView_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (mainView.SelectedNode == null)
{
Point ClickPoint = new Point(e.X, e.Y);
Point ScreenPoint = mainView.PointToScreen(ClickPoint);
Point FormPoint = this.PointToClient(ScreenPoint);
cntxtMenuTreeNPCCreate.Show(this, FormPoint);
}
}
}
Last edited by bixel; January 3rd, 2010 at 07:15 PM.
-
January 3rd, 2010, 07:14 PM
#2
Re: Right Click in TreeView not responding
Solved!
I initially created the Event in the TreeView's MouseClick Event, however I doubleclicked the TreevView's MouseDown Event to create the method and copied the same code over. Apparently it works like a charm in MouseDown - but will not register in MouseClick
Code:
private void mainView_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (mainView.SelectedNode == null)
{
Point ClickPoint = new Point(e.X, e.Y);
Point ScreenPoint = mainView.PointToScreen(ClickPoint);
Point FormPoint = this.PointToClient(ScreenPoint);
cntxtMenuTreeNPCCreate.Show(this, FormPoint);
}
}
}
-
January 3rd, 2010, 08:08 PM
#3
Re: Right Click in TreeView not responding
The problem with using the mouse down or the mouse click events is that it won't display the context menu when the user uses the keyboard SHIFT+F10 command.
So why not hook up the context menu using the TreeView.ContextMenuStrip property?
If you need a dynamic context menu (where the menu items change depending on the selected tree item), then override the AfterSelect event handler and change the context menu strip items based on the selected node.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|