// Create a new TreeNode with text "Root" TreeNode rootNode = new TreeNode("Root"); // Add two child nodes to the root node rootNode.Nodes.Add("Child 1"); rootNode.Nodes.Add("Child 2");
// Get the currently selected TreeNode TreeNode selectedNode = treeView.SelectedNode; // Check if a TreeNode is selected if (selectedNode != null) { // Do something with the selected TreeNode }
// Remove the selected TreeNode from the tree view control treeView.Nodes.Remove(treeView.SelectedNode);This example demonstrates how to remove a TreeNode from a tree view control. These examples are part of the System.Windows.Forms package library, which provides classes and controls for building Windows-based applications.