I think what you're looking for is a Context Menu. You can choose it from the Windows Forms, and then associate it in the TreeView in the TreeView's properties (assuming you have VS installed). Then you can fill it in at design time, or do it at runtime based on the info in this.treeView1.SelectedNode.
deletes the selected node, and is called by right clicking on a node then selecting delete. what i actually want to do is delete the node that was right clicked on. how do i do this? i assume i need to make the node under the mouse pointer selected, then delete it, but how?
Ok, I went through this as well and I came up with a solution. Don't know if it's the best one or not, but it works. The first thing you need to do is have have a MouseDown event handler for the TreeView.
in InitializeComponents
this.treeModify.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeMouseDown);
That will make sure that whatever node you right click on will be the SelectedNode when you go to use your ContextMenu. This seems a bit ugly to me, but it was the only way I could get it to work. Any other suggestions are welcome =).
here's a new one for you though. how can i change the order of nodes within their respected parent (increment, decrement, move to top, move to bottom)?
Allrighty, this one I haven't really done before, but I reckon you could do something like:
private void moveNode(TreeNode myNode, int NodeToMove, int WhereToMoveIt)
{
myNode[WhereToMoveIt] = (TreeNode)myNode[NodeToMove].Clone();
myNode[NodeToMove].Remove();
}
So if you wanted to move a node to the top say, you would call it as so:
moveNode(myNode, myNode.SelectedNode.Index, 0);
Or something along those lines anyway. That's sort of off the top of my head so I don't recommend cutting and pasting that code directly =), but it seems to me it should work.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.