I am using monodevelop, and did a nodeview, now I want to get the data of the selected field just clicking the mouse
how can ido that?
I would like to try to use target signals. but what should I use?
You can access the data of the selected node by your_nodeview.NodeSelection.SelectedNode.
Depending on what you mean by "just clicking the mouse", you can use either the NodeView.NodeSelection.Changed event, or the EventBox.ButtonPressEvent event.
1) The NodeView.NodeSelection.Changed event is raised whenever the selected node of your nodeview is changed. In particular, when you click the mouse on some node that is not selected, it becomes selected and the event is raised. You can see an example of using this event here.
2) If you wrap your nodeview in an eventbox, then you can catch the event that the mouse is clicked on your nodeview. You can see an example here.
Related
I have this code:
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (treeView1.SelectedNode.Nodes.Count == 0)
{
MessageBox.Show("The node does not have any children.");
}
}
When a treeView node which has no children is clicked, there seems to be a lag on the event firing.
For example:
I click on a parent node with children - MessageBox does not fire
I click on a child node without children - MessageBox does not fire
I click on a child node without children again - Messagebox fires
I click on a parent node with children - Messagebox fires
I click on a parent node with children again - messagebox does not fire.
During debug, the SelectedNode.Count value seems to be the number from the click before it.
What is going on here?
Your problem stems from the fact that the OnNodeMouseClick is fired before any selection-related events (OnBeforeSelect & OnAfterSelect) which means the SelectedNode you're inspecting has not been updated yet.
If you only care about the selection changing, then subscribe to BeforeSelect (with the ability to cancel the selection) or AfterSelect instead. This will handle changing selections using the keyboard as well.
Unlike the selection-related events, NodeMouseClick will still trigger even if the the selected node is not changing (e.g. you're clicking on an already-selected node). Also, as the name implies, this only works on mouse click and not when using the keyboard to navigate your tree.
To see what is actually happening in the background, you can have a look at the source code for TreeView, specifically the WmNotify method. You'll see that NodeMouseClick is triggered by a windows NM_CLICK message. It then performs a Hit Test at the clicked (x,y) coordinate to look for a node under the mouse, and if found, give it back to you inside the TreeNodeMouseClickEventArgs argument of the event.
TLDR: When subscribing to NodeMouseClick, your selection hasn't changed yet (and it might not be changing), but you can see the clicked node by inspecting the event arg. Only works when using mouse, not keyboard.
I have canvas with listbox inside it.
each child element of listbox sets eventhandler for Click event.
On canvas I set eventhandlers for
ManipulationStarted="canvas_ManipulationStarted"
ManipulationDelta="canvas_ManipulationDelta"
ManipulationCompleted="canvas_ManipulationCompleted"
My code for swiping works perfect accept one thing, it fires Click eventhandler before ManipulationCompleted eventhandler.
But for example listbox in the same time scrolls perfectly and do not fire Click event.
So basically what I need is to handle manipulation events in same way listbox do.
If this condition is true:
private void canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
{
e.DeltaManipulation.Translation.X > [some value]
....
}
I need to disable firing Click event on any child element of canvas, doesn't matter if it is inside listbox or not.
Why are you setting click handlers if you don't want them to fire?
Click fires on pointer pressed, so there's no way to tell if the user wanted to Click or to start a manipulation. You'll need to either decide based on the location clicked or a later event if you want to differentiate between "clicks" and swipes.
Instead of Click you can handle the Tap gesture along with the manipulation events. Since Tap fires on the pointer released the manipulation system will fire it if the user tap and releases in one spot and it will trigger the manipulations if the user presses and moves the pointer.
See How to handle manipulation events for Windows Phone 8 for more details.
I'm trying to put together a drag & drop solution in WPF TreeView control, using these techniques:
Dragging and dropping to a TreeView, finding the index where to insert the dropped item
When the user clicks on a TreeViewItem, first the treeViewItem_MouseLeftButtonDown gets executed, then the treeViewItem_Drop also. At every single click.
It sounds like you're calling DragDrop.DoDragDrop() from the treeViewItem_MouseLeftButton handler. The treeViewItem_Drop even is raised when the mouse button is released, so you're getting a drop event on every mouse click. Try calling DoDragDrop from a treeViewItem_MouseMove handler instead. Just make sure that the left mouse button is pressed before calling DroDragDrop. You may also want to make sure the mouse has moved a minimum distance before starting the DragDrop operation as well, such as
if(e.LeftButton == MouseButtonState.Pressed
&& horizontal_move > SystemParameters.MinimumHorizontalDragDistance)
{
DragDrop.DoDragDrop();
}
I have a c# windows form application where I have a treeView inside a tabPage of a tabControl which is a part of the main form.
For the tree view, I click on the items of the treeView which I want to select then some change happens based on my selected Items.
I am using the AfterSelect event for item selection and and the mouseUp event for undoing the selection.
The item selection and deselection happens right away with a single click (no problem). The other change with should happen based on the selected items happens after two clicks! A single click either on the item node or outside the node's area do not trigger this change. I have to click again in order to see the change. That is wired. I am not using mouse double click events for this or something similar, I am only using the events I described above.
How can this be happening? and How to resolve it? Thanks.
EDIT: I am using my own multi-selection version of the treeView and I found (using debug) that when I get the selected nodes of the tree in the AfterSelect event after the first click is zero, then it is the number of selected nodes with the second click. How come this is happening when selected nodes are added and to the current selectedNodes list with every click in the overrided OnAfterSelect event of the treeView?
here is part of tree view code:
public List<TreeNode> SelectedNodes
{
get
{
return selectedNodes;
}
set
{
removeSelectionFromNodes();
selectedNodes = value;
selectNodes();
}
}
protected override void OnAfterSelect(TreeViewEventArgs e)
{
base.OnAfterSelect(e);
base.SelectedNode = null;
List<MSTreeNode> nodes = new List<MSTreeNode>();
.
.
.
removeSelectionFromNodes();
selectedNodes.Clear();
selectedNodes.AddRange(nodes);
selectNodes();
}
Maybe Treeview is losing focus in between clicks (?). You could try setting Treeview HideSelection property to False to keep the currently selected item highlighted when the control loses focus.
I tried to use the MouseDown event instead of the AfterSelect event. I override it in the my own multi-selection version of the treeView and used in the c# application I am developing but still it did not work. I am not sure how mouse events really work. If not used carefully, you may see wired behaviors.
Well, I ended up overriding the MouseUp and MouseUp events in my treeView subclass then I created an event which listens for changes in the selectedNodes list. If a change to the selectedNodes happnes in any of the mouse events this event is triggered. Then, I used the ChangedSelectedNodes event handler of the treeview instance in my application to do the other changes when there is a change in the node selection. This time it worked as expected.
I posted this in hope that it would be beneficial to anyone else who ran into the same problem like me.
P.S. Sometimes things do not work as you expect them to be and you just have fight and go through every other possibility until you find the solution.
Disable the hide selection option and use afterSelect option
in my project that works well
I have a custom UserControl. I want to use it in a few different products, so I want something that can be implemented inside of the UserControl itself. I want to know when the user has clicked outside of the bounds of the UserControl so that I can hide it, similar to a ComboBox. How can I do that?
I tried handling the click event, but it only seems to fire if the click occured within the bounds of the control.
That's what the Capture property is designed to do. Set it to true and all mouse messages are routed to your control, even if it moves out of the window bounds. Check the e.Location property in the MouseDown event.
Hm, you may be able to accomplish what you want by listening to the GotFocus/LostFocus events. ComboBoxes give the drop downs focus when they open and close them when they lose focus.
do this
Select all controls on your form including form
In Property Window select MouseClick event
Now enter below Code in Common_MouseClick
Code:
if (!sender.Equals(yourControl))
{
yourControl.Visible=false;
}