TreeNode.Remove Method
.NET Framework 4
Removes the current tree node from the tree view control.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The following code example removes a TreeNode when the user right-clicks the mouse over it and toggles it from expanded to collapsed when the user clicks the mouse wheel over it. This example requires that you have a Form with a TreeView control on it. The TreeView should have two or more root tree nodes, each having at least one child node.
private void treeView1_MouseDown(object sender, MouseEventArgs e) { switch(e.Button) { // Remove the TreeNode under the mouse cursor // if the right mouse button was clicked. case MouseButtons.Right: treeView1.GetNodeAt(e.X, e.Y).Remove(); break; // Toggle the TreeNode under the mouse cursor // if the middle mouse button (mouse wheel) was clicked. case MouseButtons.Middle: treeView1.GetNodeAt(e.X, e.Y).Toggle(); break; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.