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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

TreeViewAdv and ContextMenuStrip

Thread ID:

Created:

Updated:

Platform:

Replies:

40148 Jan 26,2006 03:32 PM UTC Jan 31,2006 01:29 PM UTC Windows Forms 6
loading
Tags: Tools
Gordan Redzic
Asked On January 26, 2006 03:32 PM UTC

I have a treeviesadv with a contextmenustrip (in a GroupBar). 1) When the user right-clicks on an empty space (not a node) the node closest to that horizontal point is somehow selected. I have tried getting the point from the Control.MousePosition then attempting to select the node at that position to check if the node is null. But, no matter where the user clicks on the empty space (as long as a node is horizontal to that click) a node is selected. I am trying to NOT show the context menu when an empty space is right-clicked (look at outlook 2003). 2) When a user right-clicks (same GroupBar, same GroupBar item) on another panel (not the panel containing the tree, which the context menustrip is in) the context menu still pops up. If a contextmenu is "assigned" to a tree, why would it show up when something other than the tree "area" is right-clicked? Thanks, Rich

Vijayanand S [Syncfusion]
Replied On January 27, 2006 11:05 AM UTC

Hi Rich, 1. You could use the following code snippet in context menu opening event to avoid showing context menu if we click on empty space on the treeview: TreeNodeAdv node = this.treeViewAdv1.GetNodeAtPoint(this.treeViewAdv1.LastMousePositionToClient()); if (node == null) e.Cancel = true; else if (!node.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) e.Cancel = true; I have illustrates this behavior in the attached sample also. 2. I am afraid, I was not able to reproduce the problem. Could you please modify the attached sample to reproduce the problem? It will help us to resolve the issue as soon as possible. Please take a look at the sample and let me know if you have any questions. Thanks for using Syncfusion Products. Thanks, Vijay Test Sample

Gordan Redzic
Replied On January 27, 2006 03:26 PM UTC

Hi Vijay, Thanks for the quick reply and sample. Your sample solved the problem of the context menu opening when user clicks on white space. But, a node is still selected when user right clicks on white space that is horizontal to a node. I want a node to only be selected if a user selects a node. Forget about #2, it was an error in my code. >Hi Rich, > >1. You could use the following code snippet in context menu opening event to avoid showing context menu if we click on empty space on the treeview: > > TreeNodeAdv node = this.treeViewAdv1.GetNodeAtPoint(this.treeViewAdv1.LastMousePositionToClient()); > if (node == null) > e.Cancel = true; > else if (!node.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) > e.Cancel = true; > >I have illustrates this behavior in the attached sample also. > >2. I am afraid, I was not able to reproduce the problem. Could you please modify the attached sample to reproduce the problem? It will help us to resolve the issue as soon as possible. > >Please take a look at the sample and let me know if you have any questions. Thanks for using Syncfusion Products. > >Thanks, >Vijay > >Test Sample

Vijayanand S [Syncfusion]
Replied On January 27, 2006 04:26 PM UTC

Hi Rich, Thanks for the update. Please try with the following code to avoid selection when you right click on the TreeViewAdv: private void treeViewAdv1_MouseDown(object sender, MouseEventArgs e) { this.treeViewAdv1.BeginUpdate(); if(this.treeViewAdv1.RMouseDownNode!=null) if (e.Button == MouseButtons.Right && this.treeViewAdv1.RMouseDownNode.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) { this.treeViewAdv1.SelectedNode = this.treeViewAdv1.RMouseDownNode; } } private void treeViewAdv1_MouseUp(object sender, MouseEventArgs e) { this.treeViewAdv1.EndUpdate(true); } Please take a look at the attached modified sample which illustrates the above functionality and let me know if this resolves your requirement. Thanks, Vijay Modified Sample

Gordan Redzic
Replied On January 30, 2006 10:46 PM UTC

Unfortunately, this causes the nodes (parent nodes) to not open and close consistently. Look at you sample and try to open close the nodes using the mouse buttons. >Hi Rich, > >Thanks for the update. > >Please try with the following code to avoid selection when you right click on the TreeViewAdv: > > private void treeViewAdv1_MouseDown(object sender, MouseEventArgs e) > { > > this.treeViewAdv1.BeginUpdate(); > if(this.treeViewAdv1.RMouseDownNode!=null) > if (e.Button == MouseButtons.Right && this.treeViewAdv1.RMouseDownNode.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) > { > this.treeViewAdv1.SelectedNode = this.treeViewAdv1.RMouseDownNode; > } > } > > private void treeViewAdv1_MouseUp(object sender, MouseEventArgs e) > { > this.treeViewAdv1.EndUpdate(true); > } > > >Please take a look at the attached modified sample which illustrates the above functionality and let me know if this resolves your requirement. > >Thanks, >Vijay > >Modified Sample

Vijayanand S [Syncfusion]
Replied On January 31, 2006 10:55 AM UTC

Hi Rich, Sorry for the inconvenience. Please replace the following code in the MouseDown event. Improper place of BeginUpdate method caused the painting problem. if (e.Button == MouseButtons.Right) { this.treeViewAdv1.BeginUpdate(); if (this.treeViewAdv1.RMouseDownNode != null) if (this.treeViewAdv1.RMouseDownNode.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) { this.treeViewAdv1.SelectedNode = this.treeViewAdv1.RMouseDownNode; } } Please let me know if you still face this problem. Thanks, Vijay

Gordan Redzic
Replied On January 31, 2006 01:29 PM UTC

Hi Vijay, That did it, thanks for all your help! >Hi Rich, > >Sorry for the inconvenience. > >Please replace the following code in the MouseDown event. Improper place of BeginUpdate method caused the painting problem. > >if (e.Button == MouseButtons.Right) > { > this.treeViewAdv1.BeginUpdate(); > if (this.treeViewAdv1.RMouseDownNode != null) > if (this.treeViewAdv1.RMouseDownNode.TextBounds.Contains(this.treeViewAdv1.LastMousePositionToClient())) > { > this.treeViewAdv1.SelectedNode = this.treeViewAdv1.RMouseDownNode; > } > } > >Please let me know if you still face this problem. > >Thanks, >Vijay

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;