472,958 Members | 1,614 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 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 11520
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.