Hi,
"NodeMouseClick" in Ultra Tree View for getting the Context menu strip.
M.
mansi,
You can use the contextmenu property of the tree itself if all you want to do is show a context menu for a right click on a node. If you are using columns in the tree (e.g., OutlookExpress style), you can set up a context menu for the editor control assigned to the column.
As far as working with a nodemouseclick, in a Tree_MouseDown event handler you can use a hittest as in this code:
Dim hittestnode As UltraTreeNode = Me.MyTree.GetNodeFromPoint(Me.MyTree.PointToClient(Me.MousePosition)) If hittestnode Is Nothing Then Exit Sub
' Check for right click to get contextmenu If e.Button = MouseButtons.Right Then Exit Sub
' Get reference to cell under mouse position Dim cell As UltraTreeNodeCell = CellFromPoint(Me.MyTree, Me.MousePosition) If cell Is Nothing Then Exit Sub
Etc.
Hope this helps,
JC
I recommend using MouseUp rather than MouseDown. I think if you experiment with other applications you will find that context menus are always shown on MouseUp, not MouseDown. Using MouseDown can cause problems with mouse messages because the context menu eats the MouseUp and some controls will get confused when they get a MouseDown with no MouseUp.
I am using Mouse down event for displaying the context menu strip on a tree node.I dont want the Context menu to appear on the + node.how can i avoid that?
Thanks,Mansi
/// <summary>/// Handles the UltraTree's MouseDown event./// </summary>private void UltraTree_MouseDown( object sender, MouseEventArgs e ){ if ( e.Button == MouseButtons.Right ) { UltraTree tree = sender as UltraTree; UIElement controlElement = tree != null ? tree.UIElement : null; UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint( e.Location ) : null; NodeSelectableAreaUIElement nodeElement = null;
while ( elementAtPoint != null ) { nodeElement = elementAtPoint as NodeSelectableAreaUIElement; if ( nodeElement != null ) break;
elementAtPoint = elementAtPoint.Parent; }
if ( nodeElement != null ) { // If you get in here, the right mouse button // was pressed on the node's selectable area, which does // not include the expansion indicator. } }}
Thanks for the reply.The solutions works for me.Could you please explain what exactly is happenning in this? I didnt get the meaning of UIElement and NodeSelectableAreaUIElement.
How can i position my Context menu generated through short cut keys(SHIFT +F10) at the node itself.The context menu is generated at the right position when i do a right click but when i press the short cut keys to generate this,the context menu appears far away from the node.I am facing this Problem both in Ultra tree and in Ultra grid.
Thanks.
I am still unable to position my context menu generated through shortcut at the selected node or the selected cell/row itsel both in Ultra Tree and Ultra win grid.Please help me in finding the solution asap.
Thanks,
M
After investigating Infragistic's code using Reflector I see that when context menu is opened via keyboard, it is shown at the center of the parent control and there is no way to override this behavior. So I've tried to do something similar to what UltraToolbarsManager.SetContextmenuUltra does but simplified. It works similar to Windows Explorer.
I've created a class inherited from UltaTree and added the following code:
private bool contextMenuShortcutPressed_;public MyTree(){ KeyDown += (sender, e) => { if (e.KeyCode == Keys.Apps || (e.KeyCode == Keys.F10 && e.Modifiers == Keys.Shift)) { contextMenuShortcutPressed_ = true; } };}public void SetContextMenu(PopupMenuTool popupMenuTool){ if (ContextMenu != null) { ContextMenu.Dispose(); } ContextMenu = new ContextMenu(); ContextMenu.Popup += (sender, e) => { Point screenPoint; if (contextMenuShortcutPressed_) { Point controlPoint; var activeNode = ActiveNode; if (activeNode != null) { var labelElement = activeNode.UIElement.GetDescendant(typeof(EditorWithTextUIElement)); var activeNodeRect = labelElement == null ? activeNode.UIElement.Rect : labelElement.Rect; controlPoint = new Point(activeNodeRect.X, activeNodeRect.Y + activeNodeRect.Height / 2); } else { var rect = UIElement.Rect; controlPoint = new Point((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2); } screenPoint = PointToScreen(controlPoint); } else { screenPoint = MousePosition; } contextMenuShortcutPressed_ = false; popupMenuTool.ShowPopup(screenPoint, Rectangle.Empty, DropDownPosition.BelowExclusionRect); };}
The ContextMenu class exposes a Show method, which takes the control and a location as relative to the control's coordinate system. I don't know of any event that fires when it is about to be displayed.
I have the same problem as malli_436. I want context menu to be shown near the active node when Shift+F10 or "Menu" keyboard key is pressed.
Is there any event like "before context menu open" where I can set the position of the context menu?