Search

Monday, December 1, 2014
0 comments

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

6:27 AMMonday, December 1, 2014
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#

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top