We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

TreeViewAdv right-click selection behavior

Hello, I have a context menu attached to my TreeViewAdv and, like everyone else, I format the menu items and their behavior based on the "which" and "how many" of the nodes are selected. Currently, if you r-click beyond the right edge of a node, that node still get selected (even with full-line select off), at least while the popup is present. Left/middle clicks do not do this. How do I turn off r-click selection when the point is beyond the edge of the node? Do I have to interrupt some click event, calculate the bounding box of the node (root lines, images, text, etc), determine if the click is in the box or not, then do the right thing? I would like my TreeViewAdv to respond to r-clicks in the following manner: If the click is outside of the "in use" portion of the tree (below or to the right of nodes) the current selections should be cleared. If the click occurs on top of an unselected node, that node is selected or added to selection, depending on meta keys currently in use. If the click occurs on top of a selected node, no change to selection is made. Most of this behavior exists, or is easily implemented. But I can''t figure out how to stop the "out-of-bounds" r-click selection. Thanks for reading; any suggestions are appreciated. Keith

4 Replies

AD Administrator Syncfusion Team April 20, 2005 07:18 PM UTC

Hi Keith, The default right-click behavior doesn''t select the node, but rather sets the RMouseDownNode property to that node. This allows you to perform actions on a right-click without manually calculating which node was clicked. Of course, as you noticed, it doesn''t allow as fine a level of control as a hit test on the Node label. To disable this, add the following line of code to your MouseDown event handler (Inside your "if (e.Button == MouseButtons.Right)" block would be best): this.treeViewAdv1.RMouseDownNode = null; Hope this helps. Regards, Gregory Austin Syncfusion Inc.


AD Administrator Syncfusion Team April 21, 2005 01:21 AM UTC

>Hi Keith, > > The default right-click behavior doesn''t select the node, but rather sets the RMouseDownNode property to that node. This allows you to perform actions on a right-click without manually calculating which node was clicked. Of course, as you noticed, it doesn''t allow as fine a level of control as a hit test on the Node label. > > To disable this, add the following line of code to your MouseDown event handler (Inside your "if (e.Button == MouseButtons.Right)" block would be best): > >this.treeViewAdv1.RMouseDownNode = null; > > >Hope this helps. > >Regards, >Gregory Austin >Syncfusion Inc. Greg, Thanks for the reply. I was concerned that I''d have to calculate the rect I''d need for the hit test, but I see that TreeNodeAdv.TextAndImageBounds gives me just what I''d need. Between that and your suggestion I think I''ll be able to get things working as I''d like. Keith


SK Shanmugam Krishnappa November 9, 2007 01:39 PM UTC

> The default right-click behavior doesn't select the node, but rather sets the RMouseDownNode property to that node.

I my case, the node on which the Right-Click is made is actually getting selected. Could you please help me rectify this one?
Version :5.202.0.25



RA Rajagopal Syncfusion Team December 28, 2007 10:26 PM UTC

Hi Shanmugam,

To prevent the right click from making any selection in a TreevViewAdv, you could derive the TreeViewAdv and override the OnMouseDown. In the override method dont call the base for right click.

public class MyTreeViewAdv : TreeViewAdv
{
protected override void OnMouseDown(MouseEventArgs e)
{
if(e.Button != MouseButtons.Right)
base.OnMouseDown(e);
}
}

Let us know if you have any further questions.

Regards,
Rajagopal


Loader.
Live Chat Icon For mobile
Up arrow icon