ComponentOne TreeView for WinForms
Step 2: Creating Nodes in TreeView
Quick Start > Step 2: Creating Nodes in TreeView

You can create nodes in TreeView either by using designer or through code in your application.

Using Designer

To create nodes in TreeView using designer, complete the following steps:

  1. Click the Smart Tag, and select Edit columns.
    C1TreeColumn Collection Editor appears.
  2. Enter the relevant name and header text in the Name and the HeaderText fields respectively.



  3. Close C1TreeColumn Collection Editor.
  4. Click the Smart Tag, and select Edit nodes.
    TreeNodes Editor appears.
  5. Click Add to create a top-level node.
  6. Specify a custom label for the node in the Value property.
  7. Click Add child to add a child node to the selected node.
  8. Specify a custom label for the child node in the Value property.
  9. Repeat steps 7 to 10 as required in the application.

       
       
  10. Click OK to save the changes.

Through Code

To create nodes in TreeView programmatically, complete the following steps:

  1. Create new instances of a node.
  2. Add the parent node to the TreeView nodes collection.
  3. Set the value of the parent node.
    ' create new instances of node
    Dim node1 As New C1.Win.TreeView.C1TreeNode()
    Dim node2 As New C1.Win.TreeView.C1TreeNode()
    
    ' add parent node to the TreeView nodes collection
    C1TreeView1.Nodes.Add(node1)
    
    ' set the value of parent node
    node1.SetValue("Reports")
    
    // create new instances of node
    C1.Win.TreeView.C1TreeNode node1 = new C1.Win.TreeView.C1TreeNode();
    C1.Win.TreeView.C1TreeNode node2 = new C1.Win.TreeView.C1TreeNode();
    
    // add parent node to the TreeView nodes collection
    c1TreeView1.Nodes.Add(node1);
    
    // set the value of parent node
    node1.SetValue("Reports");
    
                   
  4. Add the child node to the parent node.
  5. Set the value of the child node.

    ' add child node to parent node
    node1.Nodes.Add(node2)
    
    'set the value of child node
    node2.SetValue("May Sales")
    
    // add child node to parent node
    node1.Nodes.Add(node2);
    
    //set the value of child node
    node2.SetValue("May Sales");
    
  6. Repeat steps 3 to 7 to add more parent nodes and child nodes.