The basic operation of the 1 TreeView tree
Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Use of the Using system.linq;using system.text;using system.threading.tasks;using system.windows.forms;namespace TreeView { Public partial class Form1:form {public Form1 () {InitializeComponent (); }//Add root node private void Button2_Click (object sender, EventArgs e) {string nodeName = Textb Ox1. Text; int LL = nodename.length; if (nodeName! = null && nodename.length > 0) {//treenode represents a node object, TREEVIEW1.NODES.ADD The return value of (NodeName) is now the name we want to add to the NodeName node. TreeNode node = TREEVIEW1.NODES.ADD (NodeName); } else {MessageBox.Show ("Please set the node name! "); }}//Add child node private void Button3_Click (object sender, EventArgs e) {string Nodenam e = TextBox1.Text; GetUser-selected nodes TreeNode node = Treeview1.selectednode; if (node! = null) {if (Nodename.length > 0) {node. Nodes.Add (NodeName); } else {MessageBox.Show ("Please set the name of the child node!") "); }} else {MessageBox.Show ("Check the root node of the child node you want to add!"); }}//Clear all nodes private void button1_click (object sender, EventArgs e) {DialogResult D R= MessageBox.Show ("Are you sure you want to empty all nodes?" "," Warning ", Messageboxbuttons.yesno); if (Dr. ToString () = = "Yes") {treeView1.Nodes.Clear (); }}//delete the selected node private void Button4_Click (object sender, EventArgs e) {TreeNode nodes = Treeview1.selectednode; if (node! = null) {treeView1.SelectedNode.Remove (); } else { MessageBox.Show ("Please select the node you want to delete!") "); }}//Expand the selected node private void Button5_click (object sender, EventArgs e) {if (treeView1 . SelectedNode! = null) {TreeView1.SelectedNode.Expand ();//expand () Method: Expand the node tree//tree View1.SelectedNode.ExpandAll (); ExpandAll () Method: Expands all descendant nodes} else {MessageBox.Show ("SELECT nodes to expand!"); }}//Close selected "Expand Node" private void Button6_click (object sender, EventArgs e) {if (t Reeview1.selectednode! = null) {treeView1.SelectedNode.Collapse ();//Close the expanded selected node} else {MessageBox.Show ("Please select the node you want to close!"); } } }}
TreeView Tree Menu Node