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
lievencardoen said:- 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.
You could select the node on a MouseDown. Use GetNodeFromPoint to determine which node to select and/or activate.
lievencardoen said:- Is there a way to hide certain menuitems or grey them out when the TreeNode is of a certain type?
Again, you could do this in the MouseDown, depending on which node is under the mouse.
lievencardoen said:- Is there a way to not show the ContextMenu at all in case of a certain type of TreeNode?
You could remove the ContextMenu in MouseDown.
lievencardoen said:- 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'm not sure I follow you. Unless the same ContextMenu is being used for more than one tree, there should be no ambiguity. If it is being used by more than one tree, then you need to keep track of which tree the menu is being displayed for - once again, MouseDown is a good place to track this.
Let me know if you have trouble getting any of this to work and I can whip up a quick sample for you.
I'll have a look at it now, so I'll get back to you. One question though, isn't the answser Dimitar gave the same? Or would you implement it differently?
Yeah, they are basically the same. My response was 2 minutes after his, so I think I didn't see his reply when I posted mine - we were both posting at the same time. :)