vi*******@yahoo.com wrote:
I have a treeview with a ContextMenu attached. When i click on a node,
AfterSelect fires but does not fire when right clicked (the context
menu pops up).
(Background: I have loaded a list of disk file names onto the tree and
have to open the file thru the contextmenu for editing. It opens the
file whose treeview node was selected earlier using a left mouse
click).
That's a bug in the current treeview. Create a routine which sets the
context menu accordingly to the current selected node.
Then, in the mousedown event (!), check if the button is the right
one, if so, first set the selected node and then call your contextmenu
set routine like this:
private void _mainTreeView_MouseDown(object sender, MouseEventArgs e)
{
// select the node the mouse is over through code. The select event is
not fired if its the same
// node. Only act if it's the RMB.
if(e.Button != MouseButtons.Right)
{
return;
}
// Store the selected node (can deselect a node).
_mainTreeView.SelectedNode = _mainTreeView.GetNodeAt(e.X,e.Y);
// set the right contextmenu with the selected node.
SetNodeSpecificSettings();
}
In afterselect, you too call your context menu specific settings
routine.
Frans
--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------