TreeView Tree Menu Node

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.