Windows Form: How to create child node of selected root node of treeview in c#

Basically Tree View contains two things, first one is root node and second one is child node. If you want to create root node in the Tree View then use Tree Node class. Now in this example, we want to create a child node inside the existing root node. So first to create the root node, Follow these instruction to create the root node inside the tree view control.

  1. Add Tree View control in the design form.
  2. Add Root Node in it by right click on Control.
Windows Form: How to create child node of selected root node of treeview in c#








3. Add one Button control and one TextBox control in the design form.
4. Raise the Button Click event, Copy this code and paste into Button_Click event handler

 private void button1_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;
            node.Nodes.Add(textBox1.Text);
        }

Code generate the following output


Windows Form: How to create child node of selected root node of treeview in c#

Comments

Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites