473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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
3 11579
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sreepathi Rao Konchada | last post by:
Hi, Is there any way that we can find the previously selected Treeview node details. I mean is there any build in function available to find the previously selected node of the Treeview in...
7
by: Michael C | last post by:
Hi all, I half-resolved my previous TreeView issue. Now I was wondering if anyone knows of a way to keep a TreeNode from being highlighted when it is left-clicked? It seems like there should...
6
by: Tim | last post by:
Hi I have a form with a treeview on it. When I select a particular node it adds/shows a tab on the form. The treeview node remains selected as it should. The user can close the tab or remove the...
0
by: OpticTygre | last post by:
Is there a way to force the afterselect event of a treeview control to fire even if the same node has been selected? During normal behavior, the afterselect event doesn't fire if the same node is...
7
by: amruta | last post by:
the code below dows not let me get the parent child view... all the nodes are show in one line only... also i need them to be collasped ... Thanks ..
0
by: Treeview Trouble | last post by:
I have an application where there are two radio buttons each of which populates a treeview control with a directory structure. Each radio button corresponds to a different directory which may or...
4
by: Xenomorph | last post by:
I have a program where you click an item on the TreeView on the left, and then work with whatever pops up on the right. There are many entries on the TreeView, and when you click something on the...
9
by: auntiejack56 | last post by:
Hi, I've got a treeview, and I want to display the node text property that I have a) clicked on or b) highlighted using the up or down arrows
2
by: govolsbaby | last post by:
Hi All I've got a treeview with checkboxes. I want the user to be able to toggle the checkbox by click on the checkbox OR by clicking on the node text. So I've added an afterselect event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.