I was just struggling with this exact same problem, and came up with a
solution which I like/dislike as much as the other suggestions:
private void tvX_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
if (e.Button == MouseButtons.Right) {
TreeNode tn = tvX.GetNodeAt(e.X, e.Y);
if (tn == null) {
return;
}
// This is awkward
if (tn.ImageIndex == 2) {
tvX.ContextMenu = null;
} else {
tvX.SelectedNode = tn;
tvX.ContextMenu = ctxtMenu_tvX;
}
}
}
BTW, my setting the selected node is my solution to another reasonably
FAQ in this group (and with other UI frameworks I've used): how to map
a context menu item selection to a node in the tree.
If someone has an elegant solution to either of these problems, one that
preferably doesn't involve hooking the Win32 event loop, I would
appreciate a post.
- Eric
"Peter Zentner" <Peter.Zentner@_RE_MOVE_web.de> wrote in message news:<#S**************@tk2msftngp13.phx.gbl>...
Hi all,
if I assign a context menu to a treeview and popup the contextmenu with the
APP-key the context menu appears in the center of the treeview control and
not at the selected treenode. Is there a chance to change this behaviour?
Regards
Peter