Quick Start

The following quick-start guide will take you through the basics of TreeView control.

This quick start will guide you through the steps of creating a simple .NET application using the TreeView control. Follow the steps below to get started:

Step 1: Adding TreeView to the Application

To add the TreeView control to your application, complete the following steps:

  1. Create a new Windows Forms Application.
  2. In the Design view, drag and drop the C1TreeView control to the form from the Toolbox.
    The TreeView control appears with Column1 added by default.
  3. Click the Smart Tag, and select Dock in Parent Container
    You have successfully added the TreeView control to the application.

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.

    Column collection editor
                       
  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.

    Node editor
  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.
    C#
    Copy Code
    // 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");
    
    VB
    Copy Code
    ' 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")
    
  4. Add the child node to the parent node.
  5. Set the value of the child node.
                                                
    C#
    Copy Code
    // add child node to parent node
    node1.Nodes.Add(node2);
    
    //set the value of child node
    node2.SetValue("May Sales");
    
    VB
    Copy Code
    ' 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.

Step 3: Running the Application

Now that you have successfully created nodes in TreeView, you just need to run the application.

The following output appears once you have run the application.

 Nodes in treeview