I have an UltraTree for which I need different ContextMenu's for different kinds of TreeNodes.
Currently I managed to create a ContextMenu and assign it to the UltraTree. The questions I have are:
- It seems that when you right click on a Node, that Node isn't selected. Is there a way to select it when it's right clicked? That would make it clear to the user on which node an action is performed.
- Is there a way to hide certain menuitems or grey them out when the TreeNode is of a certain type?
- Is there a way to not show the ContextMenu at all in case of a certain type of TreeNode?
- If in the MenuItem click event the TreeNode is not passed, how can you get a reference to the TreeNode that was right clicked?
I don't know if it's possible to create a small example showing these things? Or are there examples around (in the installation? Documentation?)?
Kind regards, Lieven Cardoen
Hello Lieven,
Thank you for contacting Infragistics Developer Support.
What you could do in order to implement a ContextMenu with these functionalities is to handle when the menu is going to be show yourself (in the MosueDown event of the UltraTree), instead of setting it to the ContextMenu property of the UltraTree. This will allow you much greater control for when the menu will appear and the state of its items. Using this approach here is what you could do to implement the functionalities you requested:
1. While the UltraTree doesn’t have NodeMouseClick event you can still use the MouseDown event and get the node with the help of the GetNodeFromPoint method of the UltraTree. Then you can set its selected property to true.
2. After you have the node that was clicked, you can check its type and you can set the Enabled or Visible properties based on your custom needs.
3. You can check if the node is of certain type before calling the ContextMenu.Show() method from the MouseDown event.
4. If you have selected the node previously you could use the UltraTree SelectedNodes property as this will be the node that the user has clicked. Alternatively on MouseDown you could set the Tag property to the clicked node and then you will have access to it from all of the MenuItems.
I have attached a simple sample which demonstrate these suggestions.
Please let me know if you have any additional questions.
very clear and succint; follow 1,2,3 at least.