467,075 Members | 968 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,075 developers. It's quick & easy.

TreeView AfterSelect Does not fire on Right click [ C# ]

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).

Any solutions?

Thanks!

Vijay

Nov 17 '05 #1
  • viewed: 10969
Share:
3 Replies
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#)
------------------------------------------------------------------------
Nov 17 '05 #2
Not convinced it's a bug, since that behaviour is still present in framework
2.0b2.
I don't think the afterselect fires (at all) if right mouse button clicked ,
so the last part of your solution would not be implemented there - in fact I
would have thought that he would implement that part from the context menu
item click events.

Br,

Mark.

"Frans Bouma [C# MVP]" <pe******************@xs4all.nl> wrote in message
news:xn***************@news.microsoft.com...
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#)
------------------------------------------------------------------------

Nov 17 '05 #3
I tried out the above and it works just fine. Now instead of the
automatic ContextMenu i display the ContextMenu using the Show method.

Thanks a lot!

vijay

Frans Bouma [C# MVP] wrote:
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#)
------------------------------------------------------------------------


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sreepathi Rao Konchada | last post: by
7 posts views Thread by Michael C | last post: by
6 posts views Thread by Tim | last post: by
reply views Thread by OpticTygre | last post: by
7 posts views Thread by amruta | last post: by
9 posts views Thread by auntiejack56 | last post: by
2 posts views Thread by govolsbaby@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.