Hello sir,
Good morning,
I'm using ultra-tree in my windows appl.In my appl there is a requirement that when user double click on a node,it need to be open a popup from.I'm trying to use tree-view double click event,but the problem is if user select anode and double click outside the node(even the tree-view scroll bar also) that popup is opening which i don't want.
So can anyone tell me is there any other event can i use for this purpose or how can i stop double click event if user click on Scrollbar.
plz help me with sample.
thanks in advance.
Hi,
Presumably, you only want to respond to the DoubleClick event of the tree if the user double-clicks on a node.
The event is not node-specific, it fires when you double click anywhere in the control. So what you need to do is determine the location of the mouse and see if it's over a node.
Here's how you do that:
private void ultraTree1_DoubleClick(object sender, EventArgs e) { UltraTree tree = (UltraTree)sender; UIElement element = tree.UIElement.LastElementEntered; if (element == null) return; UltraTreeNode node = element.GetContext(typeof(UltraTreeNode)) as UltraTreeNode; if (node == null) return; MessageBox.Show(node.Text); }
Hi Mike,
Thanks for your quick response.
this code working fine.but doesn't work when click on expansion indicators. if a node is selected, then you double click an expansion indicator(anywhere),that popup form is opening.
so how to fix that one.
There is no way to "simulate" a double click on any control that I know of. I suppose you could use Windows API and send mouse messages to the control.
Typically, this is bad practice, though. If you want your application to do the same thing it would have done if the user double-clicked on a node, then what I would do is take the code out of the DoubleClick event and put it into a method. Then call that method from the DoubleClick event and also from anywhere else you want.
Hi Mike, so if i want to simulate double click on that node by programming, how can i pass the nodeselectableareaUielement to lastelemententered, or you have a different way to simulate double click ? I try to set field lastElementEntered then call OnDoubleClick by refflection but it always reset its lastelemententered to current mouse position UIelement.
regards !
this is exactly what i needed, works great !
Thank you so much for your help.
Okay, you can narrow it down to just the selectable area of the node like this:
private void ultraTree1_DoubleClick(object sender, EventArgs e) { UltraTree tree = (UltraTree)sender; UIElement element = tree.UIElement.LastElementEntered; if (element == null) return; element = element.GetAncestor(typeof(NodeSelectableAreaUIElement)); if (element == null) return; UltraTreeNode node = element.GetContext(typeof(UltraTreeNode)) as UltraTreeNode; if (node == null) return; MessageBox.Show(node.Text); }